versión corta: (NUEVO)
demo:http://so.devilmaycode.it/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);
//output
Array
(
[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}
)
)
)
Versión larga: (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;
}
?>
fresco, voy a darle una oportunidad. También encontré esto: http://magpierss.sourceforge.net/? – Haroldo
+1 por sugerir el análisis de DOM para el análisis de RSS en lugar de utilizar una biblioteca, aunque había muchos formatos diferentes la última vez que escribí mi propio lector de RSS. – Residuum
Woah, citas extrañas que tenías allí. Lo arreglé por ti. – Franz