Today in the transfer of a mall page information, using file_get_contents or curl:
Copy Code code as follows:
$url = ' http://www.xxx.com/21/?type=23′;
$temp = file_get_contents ($url);
Echo $temp;
Get a piece of garbled, see a lot of content, including page header information, found the original page used.
Similar information, that is, content-encoding is gzip, that is, the site has gzip compression turned on. There are a variety of solutions, of course, if you use file_get_contents, you can modify this:
Copy Code code as follows:
File_get_contents ("compress.zlib://". $url);
or use Curl to complete:
Copy Code code as follows:
function Curl_get ($url, $gzip =false) {
$curl = Curl_init ($url);
curl_setopt ($curl, Curlopt_returntransfer, 1);
curl_setopt ($curl, Curlopt_connecttimeout, 10);
if ($gzip) curl_setopt ($curl, curlopt_encoding, "gzip"); The key is here.
$content = curl_exec ($curl);
Curl_close ($curl);
return $content;
}
At the same time, the reference manual above solution, can also save the gzip type of string processing is as follows:
Copy Code code as follows:
function Gzdecode ($data) {
$g =tempnam ('/tmp ', ' FF ');
@file_put_contents ($g, $data);
Ob_start ();
Readgzfile ($G);
$d =ob_get_clean ();
return $d;
}