php網(wǎng)頁抓取亂碼的解決辦法:1、使用“mbconvertencoding”轉(zhuǎn)換編碼;2、設(shè)置添加“curl_setopt($ch, CURLOPT_ENCODING, 'gzip');”選項;3、在頂部增加header代碼。
推薦:《PHP視頻教程》
php 抓取頁面亂碼
在抓取頁面的時候出現(xiàn)類似???????這樣亂碼解決方法如下
1、轉(zhuǎn)換編碼
str=mbconvertencoding(str, “utf-8”, “GBK”);
2、數(shù)據(jù)經(jīng)過gzip壓縮
curl獲取數(shù)據(jù)的時候設(shè)置添加下面的選項:
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
使用file_get_contents函數(shù)需要安裝zlib庫
$data = file_get_contents("compress.zlib://".$url);
3、獲取數(shù)據(jù)后顯示亂碼
在頂部增加下面的代碼
header("Content-type: text/html; charset=utf-8");