ERROR when trying to use s PHP to script to searh GOOGLE

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
senin
Forum Newbie
Posts: 5
Joined: Fri Jan 02, 2004 5:00 pm

ERROR when trying to use s PHP to script to searh GOOGLE

Post by senin »

I'm getting the folling error in the following piece of code
Warning: file("http://www.google.com/search?q=test") - Success in search.php on line 8

Code: Select all

function search ($searchsite="test", $query="test")
{
        $encodedquery = urlencode($query);
        $site="http://www.google.com/search?q=test";
        $results = file("$site"); //this is line 8 btw

        foreach($results as $line)
        {
                echo $line;
        }
}

search();

?>
In the above code I'm only tring to verify that the website with the google results will be retrieved. None of the variable arguments are being used.

If I only put "http://www.google.com/" it works fine. I've tried retrieving multiple sites and they all work fine. I only get the error when pages are 404. I'm just lost as to why "http://wwww.google.com/search?q=test" gives this warning when I can browse to it easily.

Thanks in advance for any help.
Last edited by senin on Fri Jan 02, 2004 5:20 pm, edited 1 time in total.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Your error levels are to low, or you would get noticed of the extra dot on line 7. Remove that and it should work. (Does here)
senin
Forum Newbie
Posts: 5
Joined: Fri Jan 02, 2004 5:00 pm

Post by senin »

I'm sorry about the dot, I'll edit it out immediately. my script doesn't contain it.

I'm still unable to retrieve the website. would you mind posting what version of PHP you are using and anything else you think could be causing the difference in our results.

thanks again.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Oh, how asuming of me. Here goes.

PHP Version: 4.3.4
Display Errors: On
Error Level: E_ALL
Register Globals: Off

Code: Select all

<?php
echo '<pre>';
echo 'PHP Version: '.phpversion()."\n";
echo 'Display Errors: '.(ini_get('display_errors') == '1' ? 'On' : 'Off')."\n";
echo 'Error Level: '.(ini_get('error_reporting') == '2047' ? 'E_ALL' : 'Not E_ALL')."\n";
echo 'Register Globals: '.(ini_get('register_globals') == '' ? 'Off' : 'On')."\n";
echo '</pre>';
?>
[Edit: Verified it yet again, and yes it works. --JAM]
[Edit II: http://phpdn.jam.nu/GoogleRetriever/ Verifying at my host also. -- JAM]
senin
Forum Newbie
Posts: 5
Joined: Fri Jan 02, 2004 5:00 pm

Post by senin »

Thanks a lot Jam. I installed the latest PHP and Apache and now it works.
Post Reply