Which function is used from gbk to utf8 in php
This article mainly introduces which function is used from gbk to utf8 in php. It is very detailed and has certain reference value. Friends who are interested must finish reading it.
In php, you can convert gbk to utf8 through the iconv function, which converts a known character set file into another known character set file, such as "iconv (" GB2312 "," UTF-8 ", $data);".
This article operating environment: Windows7 system, PHP7.4 version, Dell G3 computer.
Function: PHP converts strings from GBK to UTF8 character set iconv
1. Introduction to iconv ()
The iconv function converts one known character set file into another known character set file. For example: convert from GB2312 to UTF-8.
The iconv function is built into php5, and the GB character set is turned on by default.
2. Iconv () error
Iconv will make an error when converting the character "-" to gb2312. The solution is to add "/ / IGNORE" after the encoding to be converted, that is, after the second argument of the iconv function. As follows:
Iconv ("UTF-8", "GB2312//IGNORE", $data)
Ignore means to ignore the conversion error, and without the ignore parameter, all strings following that character cannot be saved.
3. Iconv () example
Example 1:
Example 2:
If your PHP file is UTF-8 encoded, the following code will output correctly:
If your PHP file is GB, the following code works:
In the above case, the output of the program is:
% E6%88%91%E7%88%B1%E7%99%BE%E5%BA%A6
The above is all the contents of the article "which function to use from gbk to utf8 in php". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!