How to use in PHP
Zend_Rest_Client object can be used in zend framework as mentioned below. Here the xml document returned will be parsed and converted to Zend_Rest_Client_Response object.
$client = new Zend_Rest_Client('http://query.yahooapis.com/v1/public/yql');
$client->q('SELECT * FROM flickr.photos.search WHERE text="Cat"');
$result = $client->get();
foreach ($result->photo as $val) {
/*Value of each attribute can be accessed under the node <photo>*/
echo "farm ->".$val['farm']."<br />";
echo "id ->".$val['id']."<br />";
}
Similarly, in PHP, we can use the method simplexml_load_file() which will return a parsed xml document converted into SimpleXML object.
$xml = simplexml_load_file('http://query.yahooapis.com/v1/public/yql?q=SELECT * FROM flickr.photos.search WHERE text="Cat"');
$results = $xml->results; /* Accessing parent node <results> */
foreach ($results->photo as $val) {
/*Value of each attribute can be accessed under the node <photo>*/
echo "farm ->".$val['farm']."<br />";
echo "id ->".$val['id']."<br />";
}
An online console is also present to run and test the YQL at the below mentioned URL.
http://developer.yahoo.com/yql/console/
More details can be found at
http://developer.yahoo.com/yql/guide/index.html