Hello kind people,
I'm trying to get PHP to get a web page from a server so I can parse through it and grab the data I'm looking for. But I'm having no end of trouble trying to get the simplest part -- the connection to the server and the fetching of the page -- to work.
Here's what I've written, using a salon.com article as an example of the page I'm looking for:
<?php
// Specify the host and path
$host="www.salon.com";
$path="/people/wire/2001/03/27/china/index.html";
// Open the connection and get the page
$fp = fsockopen ("$host", 80, &$errnr, &$errstr) or die("$errno: $errstr");
fputs($fp,"GET $path HTTP/1.1\n\n");
while (!$end)
{
$response .= fgets($fp, 1024);
}
//Display the page on the screen
echo "Here is the page we've gotten back: $response";
?>
...I can see no reason why this shouldn't work! Of course, I've never done this before, so there's probably something obvious that I've overlooked.
Any help that anyone has would be greatly apprecaited. Thanks a lot, in advance!
Ben