get RSS feed into php array - possible? get RSS feed into php array - possible? php php

get RSS feed into php array - possible?


Short Version: ( NEW )

demo: http://so.lucafilosofi.com/get-rss-feed-into-php-array-possible/

$feed = 'http://stackoverflow.com/opensearch.xml';$feed_to_array = (array) simplexml_load_file($feed);//OR $feed_to_array = (array) new SimpleXmlElement( file_get_contents($feed) );print_r($feed_to_array);//outputArray(    [ShortName] => Stack Overflow    [Description] => Search Stack Overflow: Q&A for professional and enthusiast programmers    [InputEncoding] => UTF-8    [Image] => http://sstatic.net/stackoverflow/img/favicon.ico    [Url] => SimpleXMLElement Object        (            [@attributes] => Array                (                    [type] => text/html                    [method] => get                    [template] => http://stackoverflow.com/search?q={searchTerms}                )        ))

Long Version: ( OLD )

<?php$rss_tags = array(  'title',  'link',  'guid',  'comments',  'description',  'pubDate',  'category',  );  $rss_item_tag = 'item';  $rss_url = 'http://www.webaddict.info/feeds/news.xml';$rssfeed = rss_to_array($rss_item_tag, $rss_tags, $rss_url);echo '<pre>';  print_r($rssfeed);function rss_to_array($tag, $array, $url) {    $doc = new DOMdocument();    $doc->load($url);    $rss_array = array();    $items = array();    foreach($doc-> getElementsByTagName($tag) AS $node) {      foreach($array AS $key => $value) {        $items[$value] = $node->getElementsByTagName($value)->item(0)->nodeValue;      }      array_push($rss_array, $items);    }    return $rss_array;  }  ?>


I believe Simplepie will do this for you as well.


If others come past, an end-to-end very simple free code example of this is on;

http://code.google.com/p/rssingest/