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>";
}
?>
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.
3 Comments to PHP Flickr Image RSS Feed Parser.
Leave a comment
Search
Recent
Topics
Comments
- Thank you, kind person. You have saved me a good deal of time. -- Adam Williams
IE8 Javascript external s[..] - Thanks for this code. I am using it with some modification to determine DST for any year, not just 2009. This has save -- Jonathan
Javascript: Figuring out [..] - I do not handle the 2AM switch over. This would be a minor bug. I checked your solution that would work I have never l -- ben
Javascript: Figuring out [..] - Your also doesn't seem to take into account the hour of the day. Daylight savings switch happens at 2AM... So there is -- Kevin
Javascript: Figuring out [..] - Matt corrected code has been posted. -- ben
Javascript: Figuring out [..]
















great post. if i want to get only 3 images how do i do so?
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.
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.