RSS 解析函数中的 PHP 解析错误
我有一个客户迫切需要一个网站,但我无法访问控制面板等信息。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
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
...在 PHP 4 中你无法做到这一点。
必须执行类似
“尝试一下”之类的操作,它才会起作用。
You can't do that in PHP 4.
Have to do something like
Try it and it will work.
您无法在 PHP 4 中链接对象调用。您必须分别对变量进行每个调用并将其全部存储。
你必须对所有这些链式调用执行此操作
至于.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.
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.
您需要将该行分解为单独的变量。 PHP 4 不喜欢->后面的括号。这样做:
每个变量的两个声明可能是多余和精简的,我不确定 PHP4 将如何响应。如果需要,您可以尝试压缩它们。
You need to break down that line into individual variables. PHP 4 does not like -> following parentheses. Do this instead:
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.
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