Skip to content

Instantly share code, notes, and snippets.

@jcleblanc
Created November 29, 2011 21:44
Show Gist options
  • Select an option

  • Save jcleblanc/1406682 to your computer and use it in GitHub Desktop.

Select an option

Save jcleblanc/1406682 to your computer and use it in GitHub Desktop.
Build Flickr Photo URLs
<?php
$yql_url = 'http://query.yahooapis.com/v1/public/yql?';
$query = 'SELECT * FROM flickr.photos.search WHERE has_geo="true" AND text="san francisco"';
$query_url = $yql_url . 'q=' . urlencode($query) . '&format=xml';
$photos = simplexml_load_file($query_url);
$result = build_photos($photos->results->photo);
echo $result;
function build_photos($photos){
$html = '';
if (count($photos) > 0){
foreach ($photos as $photo){
$html .= "<a href='http://www.flickr.com/photos/{$photo['owner']}/{$photo['id']}'
target='_blank'><img src='http://farm4.static.flickr.com/
{$photo['server']}/{$photo['id']}_{$photo['secret']}.jpg' width='75' height='75'
alt='{$photo['title']}' /></a>";
}
} else {
$html .= 'No Photos Found';
}
return $html;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment