reading a google query with simplexml

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
supasilvio
Forum Newbie
Posts: 2
Joined: Sun May 02, 2010 3:36 pm

reading a google query with simplexml

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: reading a google query with simplexml

Post 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);
supasilvio
Forum Newbie
Posts: 2
Joined: Sun May 02, 2010 3:36 pm

Re: reading a google query with simplexml

Post by supasilvio »

No errors or notices, just a blank page (even the source)....

I tried with your code but nothing changes

thanks anyway
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: reading a google query with simplexml

Post by requinix »

Your original code works fine for me.

Turn up error_reporting to E_ALL and enable display_errors.
Post Reply