有些人可以帮助我,尝试修复此错误几个小时了,似乎不知道如何
解析错误:解析错误,意外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);
答案 0 :(得分:1)
您使用的是哪个版本的PHP?
旧版本(PHP 4.x)不允许链接对象方法调用。
不允许:
$node->getElementsByTagName('pubDate')->item(0)->nodeValue
允许:
$temp = $node->getElementsByTagName('pubDate');
$temp = $temp->item(0);
$temp = $temp->nodeValue;
<强>更新强>
将问题行转换为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;
}