<item>
<title>Avoid tornado death by spinning backwards</title>
<link>www.example.com/survival_tips</link>
<pubDate>Mon, 13 Aug 2043 00:16:21 +0000</pubDate>
<dc:creator>Helen Hunt</dc:creator>
<description></description>
<content:encoded></content:encoded>
<category domain="post_tag" nicename="surv"><![CDATA[Survival]]></category>
<category domain="category" nicename="tip"><![CDATA[Tips]]></category>
<category domain="category" nicename="torn"><![CDATA[Tornados]]></category>
</item>
考虑上面的 XML。我可以通过以下方式轻松访问标题:
$feed = simplexml_load_string($xml);
foreach ($feed->channel->item as $entry) {
echo $entry->title.", ";
}
我怎样才能为所有<category...>
领域做到这一点?(我意识到如果它们被包裹在父<Categories>
标签中,我可以做到这一点,但事实并非如此。
预期输出:Survival, Tips, Tornados