解析错误:语法错误,意外'['与php 5.3 [重复]

时间:2022-05-02 22:32:09

This question already has an answer here:

这个问题在这里已有答案:

My script is working really fine on my xampp. Now I tried to upload it on the server, but it spat directly a

我的脚本在我的xampp上运行得非常好。现在我尝试将其上传到服务器上,但它直接吐了一个

Parse error: syntax error, unexpected '['

解析错误:语法错误,意外'['

in my face. :(

在我的脸上。 :(

The line which its mocking about is this one:

它嘲笑的线是这一行:

    $item = $xml->xpath($path)[0];

And I have no idea what is wrong. I tried to look on the php 5.3 changelog but did not found anything about it. (Because I have 5.3 on the server, and on xampp its an olderversion)

我不知道出了什么问题。我试着看看php 5.3更新日志,但没有发现任何关于它。 (因为我在服务器上有5.3,而在xampp上有一个较旧的版本)

The whole code block looks like this:

整个代码块看起来像这样:

$path = '//item[@id="'.$id.'"]';
if ($xml->xpath($path)) {
    $item = $xml->xpath($path)[0];
} else {
    die('<p class="error">Script Error: Code 101 - Please contact administrator</p>');
}

I am thankful for any help, I cannot seach [ with google and have no idea where it could come from, since on xampp its working fine

我感谢任何帮助,我无法与谷歌联系并且不知道它可能来自哪里,因为在xampp它的工作正常

1 个解决方案

#1


37  

Try this $item = $xml->xpath($path);
$item = $item[0];

试试这个$ item = $ xml-> xpath($ path); $ item = $ item [0];

#1


37  

Try this $item = $xml->xpath($path);
$item = $item[0];

试试这个$ item = $ xml-> xpath($ path); $ item = $ item [0];