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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.