我使用PHP和simpleXML来阅读以下RSS提要:
https://information-syndication.api.bbc.com/articles?api_key=[api_key _here]&index=indonesia-dunia&mixin=summary&mixin=hero_images&mixin=thumbnail_images
结果:
<isapi>
<results>
<article>
<headline>headline</headline>
<link>link</link>
<summary>sumary</summary>
<pubDate>date</pubDate>
<thumbnail height="360" width="640" url="http://a.files.bbci.co.uk/worldservice/live/assets/images/2016/08/23/160823220838_north_korea_missile_640x360_afp_nocredit.jpg" copyrightHolder="AFP" caption="" alt="Rudal balistik Korea Utara"/>
</article>
</results>
</isapi>
我可以获得我想要的大部分信息:
<?php
$sxml = simplexml_load_file("https://information-syndication.api.bbc.com/articles?api_key=[api_key_here]0&index=indonesia-dunia&mixin=summary&mixin=hero_images&mixin=thumbnail_images");
foreach($sxml->results->article as $name => $results)
{
echo $results->headline."<br>";
?>
<a href="<?php echo $results->link; ?>"><?php echo $results->headline ?></a><br>
<?php
echo $results->summary."<br>";
echo $results->pubDate."<br>";
}
?>
如何在
中显示图像<thumbnail height="360" width="640" url="http://a.files.bbci.co.uk/worldservice/live/assets/images/2016/08/23/160823220838_north_korea_missile_640x360_afp_nocredit.jpg" copyrightHolder="AFP" caption="" alt="Rudal balistik Korea Utara"/>
答案 0 :(得分:0)
你想获得标签的属性,在这种情况下,你想得到url =&#34; *&#34;属性值,使其迭代xml数据并访问标记写入的属性 的属性() - &GT; nameofYourAttribute 强>
$xmlElement->thumbnail->attributes()->url;