The Flickr photo feed

The Flickr photo feed

I’m not entirely sure whether this problem was a result of the PHP 5.2 upgrade and SimpleXML becoming more particular about namespaces or Flickr simply changing the namespace string in their feed. I believe it was the latter. In short, my code stopped working because the namespace lacked a trailing slash (/). It would’ve been great if Flickr had notified everyone about this first.

The code looked something like this:

<?php

$flickr_rss = simplexml_load_file('http://www.flickr.com/services/feeds/
photos_public.gne?id=49198866@N00&format=rss_200');

foreach ($flickr_rss->channel->item as $item)
{
$link   = (string) $item->link;
$media  = $item->children('http://search.yahoo.com/mrss');
$thumb  = $media->thumbnail->attributes();
$url    = (string) $thumb['url'];
$width  = (string) $thumb['width'];
$height = (string) $thumb['height'];
$title  = (string) $item->title;

// display image here
}

?>

Note the namespace listed in $item->children('http://search.yahoo.com/mrss');. It’s lacking a trailing slash. This was never a problem before, but it seems that the Flickr feed changed to include a trailing slash, so SimpleXML was no longer able to properly get the data. I simply changed it to http://search.yahoo.com/mrss/ (note the trailing slash), and all worked fine.

Blogroll sorting

This was more than likely a result of the upgrade to PHP 5.2, though I can’t be sure. My blog sorting code worked like this:

<?php

// sort by name
$name = array();
foreach ($blogs as $k => $v)
{
$name[$k] = $v['name'];
}
array_multisort($name, SORT_ASC, $blogs);

?>

Unfortunately, after the upgrade, this no longer worked. I had to add the SORT_STRING flag as a parameter to array_multisort() so that the line now reads:

<?php

array_multisort($name, SORT_ASC, SORT_STRING, $blogs);

?>

And that fixed it.

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.