2009-08-20 53 views
0

我遇到了一個腳本,顯示我的博客帳戶中最新的X篇博客文章,但是我收到了以下警告:php幫助需要,博客api/xml警告?

警告:通過引用傳遞的參數已被棄用值;如果您想通過引用來傳遞它,請修改xml_set_object()的聲明。如果您希望啓用通過引用的傳遞時間,則可以在INI文件中將allow_call_time_pass_reference設置爲true。但是,未來版本可能不再支持此功能。在上線88

這裏test.php的是代碼:

<div id="latestentries"> 
    <ul id="entrieslist"> 
    <?php 

    class RSSParser { 

     var $insideitem = false; 
     var $tag = ""; 
     var $title = ""; 
     var $pubDate = ""; 
     var $link = ""; 
     var $thr = ""; 
     var $counter = 1; 

     function startElement($parser, $tagName, $attrs) { 
      if ($this->insideitem) { 
       $this->tag = $tagName; 
      } elseif ($tagName == "ITEM") { 
       $this->insideitem = true; 

      } 
     } 

     function endElement($parser, $tagName) { 
      if ($this->counter < 5) { 
       if ($tagName == "ITEM") { 
        $title = htmlspecialchars(trim($this->title)); 
         if (strlen($title) > 35) { 
          if ($this->thr > 0) { 
           $name = $title; 
           $name = $name . " "; 
           $name = substr($name,0,31); 
           $title = $name . " ..."; 
          } 
          if (strlen($title) > 45) { 
           if ($this->thr == 0) { 
            $name2 = $title; 
            $name2 = $name2 . " "; 
            $name2 = substr($name2,0,41); 
            $title = $name2 . "..."; 
           } 
          } 
         } 
        $date = htmlspecialchars(trim($this->pubDate)); 
        $pubDate = substr($date,0,str_length-20) . "."; 
        printf("<li class='entry'><a href='%s'><span class='entrydate'>%s</span><span>%s</span>",trim($this->link),$pubDate,$title); 
         if ($this->thr == 1) { printf("<span class='entrycomments'>(%s Comment)</span>",$this->thr); } 
         elseif ($this->thr > 1) { printf("<span class='entrycomments'>(%s Comments)</span>",$this->thr); } 
        echo "</a></li>"; 
        $counter = $this->counter; 
        $this->counter = $counter + 1; 
        $this->title = ""; 
        $this->pubDate = ""; 
        $this->link = ""; 
        $this->thr = ""; 
        $this->insideitem = false; 
       } 
      } 
     } 

     function characterData($parser, $data) { 
      if ($this->insideitem) { 
      switch ($this->tag) { 
       case "TITLE": 
       $this->title .= $data; 
       $this->counter .= $counter; 
       break; 
       case "PUBDATE": 
       $counter++; 
       $this->pubDate .= $data; 
       break; 
       case "LINK": 
       $counter++; 
       $this->link .= $data; 
       break; 
       case "THR:TOTAL": 
       $counter++; 
       $this->thr .= $data; 
       break; 
      } 
      } 
     } 
    } 

    $xml_parser = xml_parser_create(); 
    $rss_parser = new RSSParser(); 
    xml_set_object($xml_parser,&$rss_parser); 
    xml_set_element_handler($xml_parser, "startElement", "endElement"); 
    xml_set_character_data_handler($xml_parser, "characterData"); 
    $fp = fopen("rss.xml","r") 
     or die("Error reading RSS data."); 
    while ($data = fread($fp, 4096)) 
     xml_parse($xml_parser, $data, feof($fp)) 
      or die(sprintf("XML error: %s at line %d", 
       xml_error_string(xml_get_error_code($xml_parser)), 
       xml_get_current_line_number($xml_parser))); 
    fclose($fp); 
    xml_parser_free($xml_parser); 

    ?> 
    </ul> 
</div> 

有人能幫助我關閉警告,或者告訴我怎麼解決? :)

回答

1

獲得$ rss_parser擺脫了 「&」:

xml_set_object($xml_parser,&$rss_parser); 

變爲: xml_set_object($ xml_parser,$ rss_parser);

根本不需要傳遞對象。它在這個版本的PHP中是自動的。

雅各

+0

謝謝你,這工作。(感覺現在愚蠢的)笑 – SoulieBaby 2009-08-20 05:53:27

+1

你不會,如果你已經看到,我所看到的代碼。 :) – TheJacobTaylor 2009-08-20 05:54:13

+0

我敢肯定大聲笑謝謝你的幫助,雖然,非常感謝! :) – SoulieBaby 2009-08-20 05:58:17