Jump to content

PHP , XML and the yahoo api!


w1ww

Recommended Posts

Hello Freaks  ;)!

 

I'm trying to use the yahoo search api, that returns a XML file and I've this script to phrase the XML, but the script returns a blank screen:

(You can see an example of what the yahoo returns here: http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=madonna&results=2)

 

<?php

$key = "MYKEY";
$query = "something";
$language = "en";



$url = "http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=".$key."&query=".$query."&results=10&language=".$language."";



$count = 10; 
        //* get the xml file
        $xml = simplexml_load_file($url);
        //* phrase all the data from the xml so we can display it
            for ($x = 0; $x < $count; $x++) {
             //* this bits for if its an rss 1 feed
            if (isset($xml->item)) {
                $item = $xml->item[$x];
            }
            //* this bits for 0.91 rss feeds
                elseif (isset($xml->Result->item)) {
                $item = $xml->Result->item[$x];
            }
            //* show the headline and the description
                echo "<a href=\"$item->Url\">$item->Title</a><br>$item->Summary<br><br>";
        }
        //* reset variables
        unset($xml);
        unset($item);
//* close the function loop




?>

 

Thank you!

 

Link to comment
https://forums.phpfreaks.com/topic/37896-php-xml-and-the-yahoo-api/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.