Posted By

ginoplusio on 05/30/10


Tagged

feed flickr spider parsing


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

jackkeller
VladNovo


Parsing Flickr Feed with PHP tutorial


 / Published in: PHP
 

URL: http://www.barattalo.it/2010/05/30/parsing-flickr-feed-with-php-tutorial/

This is a small tutorial that guide you to use a small php function that parse the flickr\'s feed and output a simply thumbs gallery. Than you can customize the output using css style sheets. Here you can find the functions, follow the link to read the tutorial.

  1. function attr($s,$attrname) { // return html attribute
  2. preg_match_all('#\s*('.$attrname.')\s*=\s*["|\']([^"\']*)["|\']\s*#i', $s, $x);
  3. if (count($x)>=3) return $x[2][0]; else return "";
  4. }
  5.  
  6. // id = id of the feed
  7. // n = number of thumbs
  8. function parseFlickrFeed($id,$n) {
  9. $url = "http://api.flickr.com/services/feeds/photos_public.gne?id={$id}&lang=it-it&format=rss_200";
  10. $s = file_get_contents($url);
  11. preg_match_all('#<item>(.*)</item>#Us', $s, $items);
  12. $out = "";
  13. for($i=0;$i<count($items[1]);$i++) {
  14. if($i>=$n) return $out;
  15. $item = $items[1][$i];
  16. preg_match_all('#<link>(.*)</link>#Us', $item, $temp);
  17. $link = $temp[1][0];
  18. preg_match_all('#<title>(.*)</title>#Us', $item, $temp);
  19. $title = $temp[1][0];
  20. preg_match_all('#<media:thumbnail([^>]*)>#Us', $item, $temp);
  21. $thumb = attr($temp[0][0],"url");
  22. $out.="<a href='$link' target='_blank' title=\"".str_replace('"','',$title)."\"><img src='$thumb'/></a>";
  23. }
  24. return $out;
  25. }
  26.  
  27. // usage example:
  28. echo parseFlickrFeed("16664181@N00",9);
  29. // you have to use css to customize it

Report this snippet  

You need to login to post a comment.