PHP's file_get_contents gets the content of the remote page. If it is gzip encoded, the returned string is the encoded garbled code
1. The solution is to find an ungzip function to convert it
2. Add to your url prefix, call
$content = file_get_contents("compress.zlib://".$url);
regardless of whether the page is gzip compressed or not, the above code can work normally!
Using the curl module can also solve the problem
Copy the code The code is 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 ;
}
http://www.bkjia.com/PHPjc/327840.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327840.htmlTechArticlePHP’s file_get_contents gets the remote page content. If it is gzip encoded, the returned string is encoded garbled code. 1. Solution, find an ungzip function to convert 2. Here you go...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn