Return to Snippet

Revision: 27219
at May 30, 2010 17:19 by ginoplusio


Initial Code
function attr($s,$attrname) { // return html attribute
	preg_match_all('#\s*('.$attrname.')\s*=\s*["|\']([^"\']*)["|\']\s*#i', $s, $x);
	if (count($x)>=3) return $x[2][0]; else return "";
}

// id = id of the feed
// n = number of thumbs
function parseFlickrFeed($id,$n) {
	$url = "http://api.flickr.com/services/feeds/photos_public.gne?id={$id}&lang=it-it&format=rss_200";
	$s = file_get_contents($url);
	preg_match_all('#<item>(.*)</item>#Us', $s, $items);
	$out = "";
	for($i=0;$i<count($items[1]);$i++) {
		if($i>=$n) return $out;
		$item = $items[1][$i];
		preg_match_all('#<link>(.*)</link>#Us', $item, $temp);
		$link = $temp[1][0];
		preg_match_all('#<title>(.*)</title>#Us', $item, $temp);
		$title = $temp[1][0];
		preg_match_all('#<media:thumbnail([^>]*)>#Us', $item, $temp);
		$thumb = attr($temp[0][0],"url");
		$out.="<a href='$link' target='_blank' title=\"".str_replace('"','',$title)."\"><img src='$thumb'/></a>";
	}
	return $out;
}

// usage example:
echo parseFlickrFeed("16664181@N00",9);
// you have to use css to customize it

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

Initial Description
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.

Initial Title
Parsing Flickr Feed with PHP tutorial

Initial Tags

                                

Initial Language
PHP