我有過想循環的XML提要,並顯示它的所有子元素,但由於某些原因,我只能輸出第一,SimpleXML的迭代只輸出第一個子元素
飼料 -
SimpleXMLElement Object
(
[title] => Lorem Ipsum
[description] => Overall description
[link] => http://someurl.com
[pubDate] => Thu, 17 Jul 2014 10:49:09 +0000
[ttl] => 123
[item] => Array
(
[0] => SimpleXMLElement Object
(
[title] => Lorem Ipsum Dolor 2
[link] => http://someurl.com
[description] => SimpleXMLElement Object
(
)
[pubDate] => Thu, 17 Jul 2014 10:49:09 +0000
[guid] => http://www.someurl.com
)
[1] => SimpleXMLElement Object
(
[title] => Lorem Ipsum Dolor 1
[link] => http://someurl.com
[description] => SimpleXMLElement Object
(
)
[pubDate] => Thu, 17 Jul 2014 10:24:51 +0000
[guid] => http://someurl.com
)
ETC
)
)
PHP -
$entries = simplexml_load_file($feed);
foreach ($entries as $entry) {
echo $entry->item->description;
}
不幸的是我可以在不影響飼料的結構,所以我需要以某種方式能夠重複下來,並在項目元素開始我的循環。想法?
讓它工作,謝謝!還有很好的解釋。 –