|
-
Mar 29th, 2009, 03:31 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] Retrieving HTML of a Page
I need to download the HTML of this page and store it in a string.
I've tried using file() and file_get_contents() and even curl().
But to no avail.
Thanks, Zach
Last edited by Zach_VB6; Mar 30th, 2009 at 12:21 AM.
-
Mar 29th, 2009, 03:57 PM
#2
Re: Retrieving HTML of a Page
file_get_contents() gets the content of this page fine. how exactly were you using it?
PHP Code:
$thedata = file_get_contents("http://items.jellyneo.net/?go=show_items&name=palm+fan&name_type=partial&desc=&cat=0&specialcat=0&status=0&rarity=0&sortby=name&numitems=20&prices=1"); echo '<xmp>' . $thedata . '</xmp>';
edit: the only thing I can think of is that if you were using it correctly, you may not have had fopen_wrappers enabled? from php.net:
A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename and List of Supported Protocols/Wrappers for a list of supported URL protocols.
Last edited by kows; Mar 29th, 2009 at 04:10 PM.
-
Mar 29th, 2009, 04:56 PM
#3
Thread Starter
Frenzied Member
Re: Retrieving HTML of a Page
As you can see here, allow_url_fopen is set to Off.
I'll have to ask JumpLine about that.
Thank you!
-
Mar 30th, 2009, 12:22 AM
#4
Thread Starter
Frenzied Member
Re: Retrieving HTML of a Page
Can you please provide me a cURL example?
-
Mar 30th, 2009, 02:16 AM
#5
Re: Retrieving HTML of a Page
I've never used curl, so I'm afraid not. the following function is something I've used in the past, and was found on php.net:
PHP Code:
function httpSocketConnection($host, $method, $path, $data) { $method = strtoupper($method); if ($method == "GET") { $path.= '?'.$data; } $filePointer = fsockopen($host, 80, $errorNumber, $errorString); if (!$filePointer) { echo 'Failed opening http socket connection: '.$errorString.' ('.$errorNumber.')<br/>\n'; return false; }
$requestHeader = $method." ".$path." HTTP/1.1\r\n"; $requestHeader.= "Host: ".$host."\r\n"; $requestHeader.= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0\r\n"; $requestHeader.= "Content-Type: application/x-www-form-urlencoded\r\n";
if ($method == "POST") { $requestHeader.= "Content-Length: ".strlen($data)."\r\n"; } $requestHeader.= "Connection: close\r\n\r\n"; if ($method == "POST") { $requestHeader.= $data; }
fwrite($filePointer, $requestHeader); $responseHeader = ''; $responseContent = '';
do { $responseHeader.= fread($filePointer, 1); } while (!preg_match('/\\r\\n\\r\\n$/', $responseHeader)); if (!strstr($responseHeader, "Transfer-Encoding: chunked")) { while (!feof($filePointer)) { $responseContent.= fgets($filePointer, 128); } } else {
while ($chunk_length = hexdec(fgets($filePointer))) { $responseContentChunk = ''; $read_length = 0; while ($read_length < $chunk_length) { $responseContentChunk .= fread($filePointer, $chunk_length - $read_length); $read_length = strlen($responseContentChunk); }
$responseContent.= $responseContentChunk; fgets($filePointer); } }
return chop($responseContent); }
it can be used like so:
PHP Code:
$host = "www.domain.com"; $path = "/file.php"; $method = "get"; $data = "field1=value1&field2=value2"; $file = httpSocketConnection($host, $method, $path, $data); //would open: www.domain.com/file.php?field1=value1&field2=value2
you can adapt it to what you're doing. it should work independently of fopen_wrappers.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|