[英]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.