Solve the problem of php collecting garbled

php crawling page garbled code

When crawling the page, there is a garbled code similar to The solution is as follows:

1. Conversion code
 

1

str=mbconvertencoding(str, “utf-8”, “GBK”);

  2. When the data is compressed by gzip and

curl to obtain the data, set and add the following options:

1

curl_setopt($ch, CURLOPT_ENCODING, 'gzip');

  To use the file_get_contents function, you need to install the zlib library

1

$data file_get_contents("compress.zlib://".$url);/* www.zjkweiqi.cn */

  3. Garbled characters

are displayed after the data is obtained. Add the following code at the top

1

header("Content-type: text/html; charset=utf-8");

Guess you like

Origin blog.csdn.net/qq_41608099/article/details/107929181