Take a pinch of RSS
<?php
$url = 'http://buzz.yahoo.com/feeds/buzzoverl.xml';
$xml = simplexml_load_file($url);
if($xml) {
foreach($xml->channel->item as $item) {
$ret[(string)$item->title] = (string)$item->link;
}
echo "<pre>"; print_r($ret); echo "</pre>";
} else echo "Can't get to Yahoo!";
?>
Output
Add a spoonful of REST
<?php
$imgs='http://api.search.yahoo.com/ImageSearchService/V1/imageSearch';
$news='http://api.search.yahoo.com/NewsSearchService/V1/newsSearch';
foreach($ret as $key=>$link) {
$url = $imgs . "?query=$key&appid=RESTDemo";
$obj = simplexml_load_file($url);
...
$url = $news . "?query=$key&appid=RESTDemo";
$obj = simplexml_load_file($url);
}
?>
A thimble of gradeschool math
And we end up with something like this
By the way, throwing a cache layer between you and whatever remote service you are
accessing tends to be a good idea. In our case we can do it like this:
<?php
$tmp = '/tmp/'.md5($q);
if(!file_exists($tmp) || filemtime($tmp) < (time()-7200)) {
$stream = fopen($url,'r');
$tmpf = tempnam('/tmp','YWS');
file_put_contents($tmpf, $stream);
fclose($stream);
rename($tmpf, $tmp);
}
$obj = simplexml_load_file($tmp);
?>