我正在尝试使用simplexml_load_file函数读取XML feed然后读取每个元素
foreach ($source_xml->channel->item as $rss) {
$title = $rss->title;
$image = $rss->children('media')->thumbnail->attributes()->url;
}
<item>
<media:thumbnail url="a.abcnews.com/images/US/…; width="384" height="288" credit="@TJReazor"/>
<media:keywords>1</media:keywords>
<title>
<![CDATA[ 5 Dead as Tornadoes Strike Dallas Area ]]>
</title>
<link>
<![CDATA[ abcnews.go.com/US/death-toll-reaches-severe-storms-south/… ]]>
</link>
<guid>
<![CDATA[ abcnews.go.com/US/death-toll-reaches-severe-storms-south/… ]]>
</guid>
<category>US</category>
</item>
但我不知道如何阅读这个元素,因为它没有结束标记,还有许多属性,如url,width等。
<media:thumbnail url="a.abcnews.com/images/US/…; width="384" height="288" credit="@TJReazor"/>
所以,如果有人试图使用PHP中的简单xml来解析它,请告诉我