简体   繁体   中英

xml to php for rss feed

I am using PHP and simpleXML to read the following rss feed:

https://information-syndication.api.bbc.com/articles?api_key=[api_key _here]&index=indonesia-dunia&mixin=summary&mixin=hero_images&mixin=thumbnail_images

result :

 <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>

I can get most of the information I want like so:

<?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>";
   }
   ?>

How to display images in the

<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"/>

你想得到标签的属性,在这种情况下,你想得到url =“*”属性值,让它迭代xml数据并访问标签的属性写属性() - > nameofYourAttribute

$xmlElement->thumbnail->attributes()->url;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM