Problems reading a URL
| From: | Stephen Phillips | Date: | Mon, 01 Apr 2002 13:22:04 +0000 |
| Subject: | Problems reading a URL | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-90940@lists.php.net to get a copy of this message | ||
Hi,
I'm working on a script to read in the results from a search engine and find out a
website's position in the results. I've run into some problems trying to read the results
in from google, it seems no matter how I try to open the page in php it still won't read the
results. I've tried using different functions to read the page, but all with no luck, it seems
that php thinks the page doesn't exist. If anyone has any experience of a similar problem
reading a file, or has any idea's on how to get it to read (maybe I missed something obvious),
please let me know,
Here's some examples of what I've tried so far,
example 1
$fp = @fopen("http://www.google.com/search?q=$keywords&num=10&hl=en&start=1&sa=N","r");
if ($fp)
{ print"The file exists!";
$contents = fread ($fp,"100000");
echo $contents;
}
else
{ print"The file does not exist"; }
example 2
$contents = @join ('', file ('http://www.google.com/search?q=$keywords&num=10&hl=en&start=1&sa=N'));
if(isset($contents)){
echo $contents;
}
else{
echo "The file does not exist";
}
I've avoided using functions like readfile, and fpassthru since they dump the file to output
imediately, and I want to get the page as a string I can search. Hope somone has some idea's
on this,
Thanks,
Steve.