Page 1 of 1

reading a google query with simplexml

Posted: Sun May 02, 2010 3:41 pm
by supasilvio
Hello, I'm trying to get the .xml I get from this page:

http://google.com/complete/search?outpu ... =microsoft

and print it to an html using this code:

Code: Select all

<?php

$xml = simplexml_load_file('http://google.com/complete/search?output=toolbar&q=microsoft');

foreach($xml->CompleteSuggestion as $CompleteSuggestion)
{
    echo '<p> '.$CompleteSuggestion->suggestion['data'].' </p>';
}

?> 
When the .xml is an existing file the code works, but when I use the link the page is blank....

thank you for helping

Re: reading a google query with simplexml

Posted: Sun May 02, 2010 3:54 pm
by John Cartwright
Are you getting any errors or notices? What about trying to load the xml as a string. I.e.,

Code: Select all

$content = file_get_contents('http://google.com/complete/search?output=toolbar&q=microsoft');
$xml = simplexml_load_string($content);

Re: reading a google query with simplexml

Posted: Sun May 02, 2010 4:02 pm
by supasilvio
No errors or notices, just a blank page (even the source)....

I tried with your code but nothing changes

thanks anyway

Re: reading a google query with simplexml

Posted: Sun May 02, 2010 7:03 pm
by requinix
Your original code works fine for me.

Turn up error_reporting to E_ALL and enable display_errors.