试图获得非对象的财产

时间:2016-10-04 03:13:03

标签: php

$xml = simplexml_load_file('http://quest7.myddt.com.br/serverlist.ashx');

echo $xml->Result->Item->Port;

//echo '<pre>';
//var_dump($xml);
  

错误:尝试获取非对象的属性修复?

1 个答案:

答案 0 :(得分:1)

已加载根元素,因此您跳过Result,然后PortItem的属性,因此您可以像数组索引一样引用它:

<?php

$xml = simplexml_load_file('http://quest7.myddt.com.br/serverlist.ashx');

if ($xml !== false){
    echo $xml->Item['Port'];
} else {
    echo "something went wrong...";
}
  

8000