致命错误:函数名称必须是第11行的字符串

时间:2014-06-26 21:26:07

标签: php domdocument

我知道有很多这些,而且我的PHP可能充满了错误(我是PHP的新手),但是我无法想象这个...它引用了“函数必须是一个字符串”第11行的错误:

<?php 

$dom=new DOMDocument();
$dom->formatOutput=true;
$dom->load('test.xml');
$searchItems=$dom->getElementsByTagName('title');
$voteItems=$dom->getElementsByTagName('vote');


for ($i=0; $i < $searchItems->length; $i++){
$value = $voteItems($i)->textContent;
$value++;
$name=$searchItems($i);
$xpath = new DOMXPath($dom);
$resulted = $xpath->query('div[@class="active"]');
$active= $div->$resulted->query('div[@class="content"]');
$names=$active->getAttribute('song');

preg_match($names, "i");

if(preg_match($names, $name )){
$voteItems($i)->length->textContent=$value;
$vote = voteItems($i)->length->textContent;
$results=array($name, $vote);
$txt=($name." scored: ".$vote." votes");
echo $txt;
}
}
?> 

这是做什么的,以防万一有更好的方法来做到这一点,它检查和我有的XML表格如下:

<playslist>
<song>
<source>imgs/Beck.jpg</source>
<title>Modern Guilt</title>
<artist>Beck</artist>
<vote>0</vote>
<plays>y</plays>
</song>
</playlist>

检查标题,并为每首歌投票,然后存储。

然后为每个获取投票标签的值,添加一个,然后使用<div>在HTML中搜索class="active",然后使用active搜索该div并找到内部div有class="content",然后返回该div的“歌曲”属性。

然后我有一个preg匹配来检查循环中当前“i”的名称是否与“song”属性中的字符串匹配。

如果匹配,则“i”的值将为其值+1。然后它将存储该名称值,并将新的投票值作为数组供我检查。

之后我想保存XML表的新变化。 (否则我会把它保存在JavaScript中)

任何提示,提示和帮助将不胜感激!作为PHP的新手,我喜欢了解更多信息!

1 个答案:

答案 0 :(得分:2)

$value = $voteItems($i)->textContent;

这是不正确的。您正尝试使用$voteItems并将其用作函数的名称。

PHP允许它:

function foo() {}
$name = "foo";
$name(); // calls foo()

但是,只有$name是字符串时才能使用。这里是$voteItems is a DOMNodeList,因此是错误消息。

the documentation看,似乎你打算写:

$value = $voteItems->item($i)->textContent;
//                 ^^^^^^^^^^