How to parse RSS Feed XML from Blogspot using PHP

Posted by in Code Snippets, Technology

Mighty PHP allows us to do just about anything our hearts desire. Copy and paste the following code to your web page, and you’ll be parsing blog posts from blogspot in no time. The nifty little simplexml_load_file function used here allows you to parse XML files with a level of ease comparable to picking teeth with a toothpick. This function alone opened up a new horizon of creativity for me. I hope you guys find this useful and come up with your own creative ways of exploiting this function for making the world (wide web) a more fun place to live in. Go make Daddy proud!

// Set name of XML file
$file = "http://[YOUR_BLOGSPOT_ACCOUNT]";
// Load specified XML file or report failure
$xml = simplexml_load_file($file) or die ("Unable to load XML file!");
// Load blog entries
$xml =  $xml ->entry;
// Run loop for the number of available entries
foreach( $xml as $row )
 // Load the entry publish time 
 $dtime = date("D jS M, Y", strtotime(strtok($row->published, 'T')));
 // Load the link of each blog entry
 $titlelink = $row->link[4][href];
 // Load the text for Comment and comment counts
 $comments = $row->link[1][href];
 $comm = $row->link[1][title][0]; 

 /* Display the contents (use your own imaginations here =).) */
 // Display publish time
   Published on: $dtime
 // Display blog entry content
 // Display number of comments