使用子阵列

时间:2016-07-19 11:08:56

标签: php xml feed

我有这个XML Feed:

<item>
    <title>Title</title>
    <media:group>
        <media:content url="http://example.it/image.jpg" type="image/jpeg">
            <media:thumbail url="http://example.it/image.jpg" type="image/png"/>
            <media:credit>Credit</media:credit>
        </media:content>
        <media:content url="http://example.it/image2.jpg" type="image/jpeg">
            <media:thumbail url="http://example.it/image2.jpg" type="image/png"/>
            <media:credit>Credit2</media:credit>
        </media:content>
    </media:group>
</item>

这是我读取它的PHP代码:

$rss = new SimpleXMLElement($url);
foreach ($rss->channel->item as $item) {
    $title = $item->title;
}

阅读没问题&#34;标题&#34;项目,但我怎样才能阅读&#34; url&#34;,&#34; thumbnail&#34;,&#34; credit&#34;对于每种媒体:内容?

------- -------解决

$rss = new SimpleXMLElement($url);
foreach ($rss->channel->item as $item) {
    $title = $item->title;
    $gallerie = $item->children('http://search.yahoo.com/mrss/')->group->content;
    foreach($gallerie as $g) {
        echo $g->attributes()['url'] ."<br/>";
    }
}

0 个答案:

没有答案