How to convert php gb2312 to utf8

藏色散人
Release: 2023-03-12 18:52:01
Original
2705 people have browsed it

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.

How to convert php gb2312 to utf8

#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);
Copy after login

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 
Copy after login

* testurl.php

getMessage(), $e->getCode()); }
Copy after login

* 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; } }
Copy after login

The original web page content is as follows:

      ͡ʾ  

ţ½«Ҫ·Ďʵ

https://www.sk666.vip

´畚°²ȫ·萕£¬Ϊ±£֏źµİ²ȫ£¬ӑ°?9½ء£

Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!