php Method to convert gb2312 to utf8: 1. Open the corresponding PHP file; 2. Check the original encoding; 3. Convert the gb2312 page to a utf8 page by using the preg_replace and iconv functions.
#The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.
php How to convert gb2312 to utf8?
Convert PHP gb2312 page to utf8 page
Use 2 functions preg_replace, iconv
$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
Reference Example of php official website
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; } }
The original web page content is as follows:
͡ʾ
ţ½«Ҫ·Ďʵ
https://www.sk666.vip
´畚°²ȫ·萕£¬Ϊ±£֏źµİ²ȫ£¬ӑ°?9½ء£
Recommended study:《PHP video tutorial》
The above is the detailed content of How to convert php gb2312 to utf8. For more information, please follow other related articles on the PHP Chinese website!