PHPでのRSS解析

投稿者:

pear XML を使えば非常に簡単です
*朝日新聞のRSSを取得する場合
  require_once(“XML/RSS.php”);
  // RSSファイルへのURIをコンストラクタの引数に渡す
  $rss =& new XML_RSS(“http://www3.asahi.com/rss/index.rdf”);
  // RSSファイルをパースする
  $rss->parse();
  // getItemsメソッドを使用して全item要素を取得
  foreach ($rss->getItems() as $item) {
    $title = mb_convert_encoding($item[‘title’], ‘UTF-8’, ‘auto’);
    $link = $item[‘link’];
    $description = mb_convert_encoding($item[‘description’], ‘UTF-8’, ‘auto’);
  }

Thank you for reading this post, don't forget to subscribe!