Aug 08
How to read RSS feed with PHP
This is probably the easiest way to read RSS feed in PHP, you use simplexml_load_file. It returns a SimpleXMLElement object. The snippet below grabs my blog’s feed and outputs in SimpleXMLElement assigned to the variable $blog. The rest is rather self explanatory.
$blog = simplexml_load_file(
"http://feeds.feedburner.com/ijustrealized",
"SimpleXMLElement",
LIBXML_NOCDATA
);
print_r($blog);
$posts = array();
foreach ($blog->channel->item as $item) {
array_push($posts, $item);
}
print_r($posts);
"http://feeds.feedburner.com/ijustrealized",
"SimpleXMLElement",
LIBXML_NOCDATA
);
print_r($blog);
$posts = array();
foreach ($blog->channel->item as $item) {
array_push($posts, $item);
}
print_r($posts);
The problem with SimpleXML is that it ignores CDATA by default. To stop that from happening, you could merge CDATA as text nodes by specifying the option constant LIBXML_NOCDATA.
Thanks for the guide dude. It’s really useful ^^
Aug 08