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
Printable View
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
file_get_contents() gets the content of this page fine. how exactly were you using it?
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: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>';
Quote:
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.
As you can see here, allow_url_fopen is set to Off.
I'll have to ask JumpLine about that.
Thank you!
Can you please provide me a cURL example?
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:it can be used like so: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);
}
you can adapt it to what you're doing. it should work independently of fopen_wrappers.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