2013-04-15 101 views
-3

可一些請幫幫我,想立即解決這個錯誤了幾個小時,不似乎知道如何解析錯誤:解析錯誤,意想不到的T_OBJECT_OPERATOR,預計「)」

解析錯誤:解析錯誤,意想不到的T_OBJECT_OPERATOR,預計 ')'

oreach ($doc->getElementsByTagName('item') as $node) { 

    if ($counter <= $limit) 
    { 
    $items = array ('title' => $node->getElementsByTagName('title')->item(0)->nodeValue,'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,'description' => $node->getElementsByTagName('description')->item(0)->nodeValue,'pubDate' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue); 
    array_push($feeds, $items); 
    } 
    $counter++; 
} 
     echo ' 
      <ul id="facebook">'; 

       foreach ($feeds as $feed) 
        { 
         $date = strtotime($feed['pubDate']); 

          echo ' 
          <li>'; 
          echo '<div class="blog_box"> 
              <div class="grid_2"> 
           <h4>'. date('jS F Y G:H' ,$date) .'</h4> 

          </div> 
         <div class="grid_6"> 
          <h1><a href="'. $feed['link'] .'" title="'.$feed['title'].'">'.$feed['title'].'</a></h1> 
          <p>'.$feed['description'].'</p> 
         </div> 
         <div align="right"> 
         <a href="'. $feed['link'] .'" class="button minimal small" title="News link">Read More</a> 
         </div> 
         <div class="clearnospacing"></div>        
       </div>      
         '; 
          echo '</li> 
        '; 
       } 

      echo '</ul> 
     '; 

,即時通訊得到的是

$items = array ('title' => $node->getElementsByTagName('title')->item(0)->nodeValue,'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,'description' => $node->getElementsByTagName('description')->item(0)->nodeValue,'pubDate' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue); 

回答

1

您正在使用什麼版本的PHP的錯誤?

舊版本(PHP 4.x)不允許鏈接對象方法調用。

不允許:

$node->getElementsByTagName('pubDate')->item(0)->nodeValue 

允許:

$temp = $node->getElementsByTagName('pubDate'); 
$temp = $temp->item(0); 
$temp = $temp->nodeValue; 

UPDATE

您的問題在線翻譯成PHP4:

$items = array(
    'title'  => get_tag_value($node, 'title'), 
    'link'  => get_tag_value($node, 'link'), 
    'description' => get_tag_value($node, 'description'), 
    'pubDate'  => get_tag_value($node, 'pubDate'), 
); 

然後在代碼中的某處添加此功能:

function get_tag_value($node, $tag){ 
    $tags = $node->getElementsByTagName($tag); 
    $tag = $tags->item(0); 
    return $tag->nodeValue; 
} 
+0

+1瞭解根源。 –

+0

它可能是php 4,目前的主機是可怕的 - 但不能移動,直到下個月:(,那麼我怎麼稱呼它? – user1761886

+0

我已經更新了我的答案與PHP4兼容的解決方案 – Cal

相關問題