SL8R.co.uk - Code Zone

Code, Code and Code

SL8R.co.uk - Code Zone header image 2

PHP: Web Service Feed Information

March 27th, 2008 · 1 Comment

Using a web service feed under REST is useful to obtain information that would otherwise be tricky to get.

For example, to get information out of Technorati (rankings etc) you could use:

$request = 'http://api.technorati.com/bloginfo?key=[key]&url=’ . urlencode(’www.jasonslater.co.uk’) . ”;
$response = file_get_contents($request);

(remember to replace the url with your own and put your API key in the section [key].

Alternatively, using the Yahoo model an example request could be something like:

$request = 'http://search.yahooapis.com/ ImageSearchService/V1/imageSearch?appid=YahooDemo& query='.urlencode('Al Gore').'&results=8';

After the data is parsed into elements check if you have simpleXML installed using php_info();

$phpobject = simplexml_load_string($response);
foreach($phpobject->attributes() as $name=>$attr)
{
  $res[$name]=$attr;
}
print_r($phpobject);
var_dump($phpobject);

Tags: Code

1 response so far ↓

Leave a Comment