-3

有人可以帮助我吗,现在尝试修复此错误几个小时,但似乎不知道如何解决

解析错误:解析错误,意外的 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);
4

1 回答 1

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;
}
于 2013-04-15T23:19:56.527 回答