运行我的代码时,出现以下错误:
Call to a member function count() on a non-object generates a fatal error.
是什么使得此代码中的非对象?什么原因导致我的代码中出现此错误错误来自此特定行$len=$xml->link->count();
如果您有合理的解决方案,请在下面发表评论/回答。如果我的代码不够深入,请告诉我。谢谢!
error_reporting(E_ALL);
ini_set('display_errors', 1);
$theFile = file_get_contents('/home/thecookie12/public_html/links.xml');
$xmlDoc = <<<'EOT'
echo $theFile;
EOT;
$theFile's
变量从links.XML
文件中获取字符串。
可以在此处找到Links.xml源代码 - http://lit.life/links.xml
$xml = simplexml_load_string($xmlDoc);
$seen=array();
$len=$xml->link->count();
for($i=0;$i<$len;$i++){
$key=(string) $xml->link[$i]->title;
if (isset($seen[$key])) {
unset($xml->link[$i]);
$len--;
$i--;
}else{
$seen[$key]=1;
}
}
echo $xml->asXML();