PHP Flickr Image RSS Feed Parser.

Updated Sept 18, 2009 Flickr changed their feed so code has been altered to continue working.

In an earlier posted an example on how to use ExtJS to do some simple effects to move images around the screen. That is great and fun and all but it really has no value unless you can apply it. In that example I used some static URL to images since the focus was on getting things moving.

Taking things a step further I decided it would be better to take that simple example and actually make it of use to someone. Flickr is a pretty commonly used site to upload photos to so I decided to focus on shifting my small example to pull photos from Flickr’s RSS feed. This would allow the app to use just change as the feed changes. Doing this did not take long.

Using Anis uddin Ahmad’s  PHP lightweight feed parser allowed me to build a rather quick parser to grab photos from Flickr.  10 minutes later I had my parser working grabbing just the photo URL’s from Flickrs RSS feed.  Here is the code and below an example of it working.


<?php
include('FeedParser.php');
$sURL = "http://api.flickr.com/services/feeds/photoset.gne?set=72157618659871441&nsid=41823576@N00&lang=en-us";

$Parser   = new FeedParser();
$Parser->parse($sURL);
 
$channels    = $Parser->getChannels();     
$items       = $Parser->getItems();  
 
foreach($items as $item){
  $sContent = $item['CONTENT'];
  preg_match("#\s?src=\"(http://(.+)\.jpg)\"(\w)*#", $sContent, $aMatches); // updated!
  
  $sImgSrc = $aMatches[1];
  echo "<img src='{$sImgSrc}'/><br>";
}
?>

THE WORKING EXAMPLE

In the future I will bring the two ideas together to have a more interactive example of what is turning out to be a simple photo gallery project.

Tags: , , , ,

Sunday, August 9th, 2009 PHP, programming, projects

3 Comments to PHP Flickr Image RSS Feed Parser.

  1. great post. if i want to get only 3 images how do i do so?

  2. max on October 18th, 2009
  3. Thank you for your kind words.

    If you wanted to do that max you could simply add a counter and break out of the loop when you hit the counter.

    For instance:

    $nCounter = 0;
    foreach($items as $item){
    if($nCounter == 3){
    break;
    }

    // rest of code from post

    $nCounter++;
    }

    I hope that helps you out.

  4. ben on October 19th, 2009
  5. BTW Max I am writing a more comprehensive version of that RSS feed reader that you may find useful I will post code once I get time. I was just in California on a trip but should get time once things settle down again.

  6. ben on October 19th, 2009

Leave a comment

Search

 

Comments