php gb2312转换为utf8的方法:1、打开相应的PHP文件;2、检查原始编码;3、通过使用preg_replace和iconv函数将gb2312页面转换为utf8页面即可。

本文操作环境:Windows7系统、PHP7.1、Dell G3电脑。
php gb2312怎么转换为utf8?
PHP gb2312页面 转换为utf8页面
用到2个函数 preg_replace, iconv
立即学习“PHP免费学习笔记(深入)”;
$html = preg_replace('/charset=gb2312/', 'charset=UTF8', $html);
// $enc = mb_detect_encoding($html);
$html = iconv('gbk', 'utf-8', $html);https://php.net/manual/en/function.iconv.php
https://www.php.net/manual/en/function.preg-replace.php
参考php官网的示例
Example #2 Using indexed arrays with preg_replace() Example #1 iconv() example
* testurl.php
getMessage(), $e->getCode()); }
* Curl.php
$u,
'apikey' => '******', // 发邮件至aiqing174@qq.com索取apikey
]);
}
public static function testURL($u) {
$api = "http://qbview.url.cn/getResourceInfo";
return self::get($api, [
'appid' => 31,
'url' => $u
]);
}
/**
* @param $host string
* @param $params array assoc
* @return mixed
* @throws Exception
*/
protected static function get($host, $params) {
$ch = curl_init();
$headers = [
"Accept: application/json",
"X-Requested-with: XMLHttpRequest",
];
$qs = self::buildQuery($params);
$fullURL = sprintf("%s?%s", $host, $qs);
curl_setopt_array($ch, [
CURLOPT_URL => $fullURL,
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_CONNECTTIMEOUT => 5
]);
$data = curl_exec($ch);
$errno = curl_errno($ch);
if ($errno) {
throw new Exception("%s\n", curl_error($ch), $errno);
}
curl_close($ch);
return $data;
}
}原网页内容如下:
͡ʾ
ţ½«Ҫ·Ďʵ
https://www.sk666.vip
´畚°²ȫ·萕£¬Ϊ±£֏źµİ²ȫ£¬ӑ°?9½ء£
推荐学习:《PHP视频教程》











