RSS 解析函数中的 PHP 解析错误

发布于 2024-09-16 18:26:16 字数 1086 浏览 11 评论 0原文

我有一个客户迫切需要一个网站,但我无法访问控制面板等信息。

PHP 版本是 4.4,这对我来说很痛苦,因为我已经习惯了 5。

第一个问题是我不断遇到:

Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ')' in D:\hshome\*******\********\includes\functions.php on line 37

这是有问题的函数:

function read_rss($display=0,$url='') {
    $doc = new DOMDocument();
    $doc->load($url);
    $itemArr = array();

    foreach ($doc->getElementsByTagName('item') as $node) {
        if ($display == 0) {
            break;
        }

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

         array_push($itemArr, $itemRSS);

        $display--;
    }
    return $itemArr;
}

以及有问题的行:

'title'=>$node->getElementsByTagName('title')->item(0)->nodeValue,

I have a client who needs a website urgently, but I have no access to information such as the control panel.

PHP Version is 4.4 Which is a pain as I'm used to 5.

The first problem is I keep getting:

Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ')' in D:\hshome\*******\********\includes\functions.php on line 37

This is the function in question:

function read_rss($display=0,$url='') {
    $doc = new DOMDocument();
    $doc->load($url);
    $itemArr = array();

    foreach ($doc->getElementsByTagName('item') as $node) {
        if ($display == 0) {
            break;
        }

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

         array_push($itemArr, $itemRSS);

        $display--;
    }
    return $itemArr;
}

And the line in question:

'title'=>$node->getElementsByTagName('title')->item(0)->nodeValue,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

北凤男飞 2024-09-23 18:26:16

PHP4 不支持对象取消引用。所以 $obj->something()->something 将不起作用。你需要做 $tmp = $obj->something(); $tmp->某事...

PHP4 does not support object dereferencing. So $obj->something()->something will not work. You need to do $tmp = $obj->something(); $tmp->something...

一绘本一梦想 2024-09-23 18:26:16

在 PHP 4 中你无法做到这一点。

必须执行类似

   $nodes = $node->getElementsByTagName('title');
   $item = $nodes->item(0);
   $value = $item->nodeValue,

“尝试一下”之类的操作,它才会起作用。

You can't do that in PHP 4.

Have to do something like

   $nodes = $node->getElementsByTagName('title');
   $item = $nodes->item(0);
   $value = $item->nodeValue,

Try it and it will work.

撞了怀 2024-09-23 18:26:16

您无法在 PHP 4 中链接对象调用。您必须分别对变量进行每个调用并将其全部存储。

$titleobj = $node->getElementsByTagName('title');
$itemobj = $titleobj->item(0);
$value = $itemobj->nodeValue;

...

'title'=>$value,

你必须对所有这些链式调用执行此操作

至于.htaccess ...你需要与控制实际服务器的人交谈。听起来 .htaccess 不允许更改您要更改的设置。

You can't chain object calls in PHP 4. You're going to have to make each call separately to a variable and store it all.

$titleobj = $node->getElementsByTagName('title');
$itemobj = $titleobj->item(0);
$value = $itemobj->nodeValue;

...

'title'=>$value,

you'll have to do it on all those chained calls

As for .htaccess ... you need to talk to someone who controls the actual server. It sounds like .htaccess isn't allowed to change the setting you're trying to change.

十年九夏 2024-09-23 18:26:16

您需要将该行分解为单独的变量。 PHP 4 不喜欢->后面的括号。这样做:

    $title = $node->getElementsByTagName('title');
    $title = $title->item(0);
    $description = $node->getElementsByTagName('description');
    $description = $description->item(0);
    $link = $node->getElementsByTagName('link');
    $link = $link->item(0);

    $itemRSS = array(
        'title'=>$title->nodeValue,
        'description'=>$description->nodeValue,
        'link'=>$link->nodeValue);

每个变量的两个声明可能是多余和精简的,我不确定 PHP4 将如何响应。如果需要,您可以尝试压缩它们。

You need to break down that line into individual variables. PHP 4 does not like -> following parentheses. Do this instead:

    $title = $node->getElementsByTagName('title');
    $title = $title->item(0);
    $description = $node->getElementsByTagName('description');
    $description = $description->item(0);
    $link = $node->getElementsByTagName('link');
    $link = $link->item(0);

    $itemRSS = array(
        'title'=>$title->nodeValue,
        'description'=>$description->nodeValue,
        'link'=>$link->nodeValue);

The two variable declarations for each may be redundant and condensed, I'm not sure how PHP4 will respond. You can try to condense them if you want.

暖树树初阳… 2024-09-23 18:26:16

DOMDocument 是 php 5 函数。你不能使用它。
您可能需要使用 DOM XML (PHP 4) 函数

DOMDocument is php 5 function.You cant use it.
you may need to use DOM XML (PHP 4) Functions

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文