loading rss feed into php

烈酒焚心 提交于 2019-12-06 05:25:09

Check this:

<?php

$feed = simplexml_load_file('http://www.hln.be/rss.xml');

foreach ($feed->channel->item as $item) {
  $title       = (string) $item->title;
  $description = (string) $item->description;

  print '<div>';

  printf(
    '<h2>%s</h2><p>%s</p>', 
    $title, 
    $description
  );

  if ($media = $item->children('media', TRUE)) {
    if ($media->content->thumbnail) {
      $attributes = $media->content->thumbnail->attributes();
      $imgsrc     = (string)$attributes['url'];

      printf('<div><img src="%s" alt="" /></div>', $imgsrc);
    }
  }

  echo '</div>';
}

?>

You can try this:

<?php

$feed = simplexml_load_file('http://www.hln.be/rss.xml');

print_r($feed);

?>

This gives you object/array structure which you can use directly instead of communicating with additional layer(i.e. DOM) on top of the data.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!