php采集亂碼的解決辦法:1、使用“str=mbconvertencoding(str, “utf-8”, “gbk”);”方法轉(zhuǎn)換編碼;2、將數(shù)據(jù)經(jīng)過gzip壓縮;3、在頂部增加“charset=utf8”代碼。
推薦:《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");