[英]PHP simplexml results in Notice: Trying to get property of non-object in error from curl
我肯定在这里做错了明显的事情:
我正在使用Curl从保存为$ result的登录中检索数据。 XML看起来像:
<data>
<option>...</option>
<option>...</option>
<option>...</option>
<items>
<item title="label">
<detail_1="abc">
<detail_2="def">
</item>
<item title="label2">
<detail_1="def">
<detail_2="ghi">
</item>
</items>
</data>
我只需要每个“项目”组中的所有数据。
我的代码:
$xml = simplexml_load_string($result);
foreach($xml->data->items->item as $item)
{
echo $item["label"].'<br>';
}
结果是
Notice: Trying to get property of non-object in ....
我以前没有使用过此功能。 请指教。
代替此echo $item["label"].'<br>';
试试这个
echo $item['title'].'<br>';
您之所以喜欢这样,是因为您要打印的是商品标签的属性
foreach($xml->data->items->item->attributes() as $key=>$val)
{
echo $val.'<br>';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.