本文介紹了解碼通過 PHP 中的 cURL 檢索的 gzipped 網頁的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在通過 curl 檢索 gzip 壓縮的網頁,但是當我將檢索到的內容輸出到瀏覽器時,我只獲得了原始 gzipped 數據.如何在 PHP 中解碼數據?
I'm retrieving a gzipped web page via curl, but when I output the retrieved content to the browser I just get the raw gzipped data. How can I decode the data in PHP?
我發現的一種方法是將內容寫入 tmp 文件,然后...
One method I found was to write the content to a tmp file and then ...
$f = gzopen($filename,"r");
$content = gzread($filename,250000);
gzclose($f);
.... 但是伙計,一定有更好的方法.
.... but man, there's got to be a better way.
這不是一個文件,而是一個由網絡服務器返回的 gzipped html 頁面.
This isn't a file, but a gzipped html page returned by a web server.
推薦答案
我使用 curl 和:
I use curl and:
curl_setopt($ch, CURLOPT_ENCODING , "gzip");
這篇關于解碼通過 PHP 中的 cURL 檢索的 gzipped 網頁的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!