Home > Backend Development > PHP Tutorial > PHP character encoding conversion tool_PHP tutorial

PHP character encoding conversion tool_PHP tutorial

WBOY
Release: 2016-07-20 11:04:27
Original
852 people have browsed it

A while ago, I saw Mr. qiushuiwuhen’s article on the conversion of gbk, unicode, and big5
but there were some minor problems
so I designed a class responsible for character conversion and corrected some of the deficiencies. , added some functions, I will continue to expand this class in the future to support more character sets
Added the following points:
unicode->gbk symbol part conversion
Euro character (€) Recognition of mutual conversion between
big5, Unicode, and GBK requires that only the common character set part is converted.
Instructions for use:
The temporary program supports the following character encoding methods:
GBK, BIG5, UTF-16BE (Unicode big-endian byte order), UTF-16LE (Unicode little-endian byte order), UTF-8
The default input encoding method is GBK, and the default output encoding method is UTF-16BE;
This category provides two functions to modify the input and output encoding methods:
Modify the input encoding method boolean SetGetEncoding(string $GetEncoding)
Modify the output encoding method boolean SetToEncoding(string $ToEncoding)
The function parameters are only The above 5 encoding methods can be used and are case-sensitive. For example, GBK cannot be written as gbk
If the setting is successful, return true. If the wrong encoding name is used, return false and display the error message
Function
string EncodeString(string $String)
is responsible for character encoding conversion and returns the converted string
Before use, please set the var $FilePath="" variable to the absolute path of the program file, otherwise it will not be found. To the data file
Example:
Convert gbk-encoded string to UTF-8 encoding:
$s="GBK encoding";
$CharEncoding=new Encoding();
$ CharEncoding->SetGetEncoding("GBK")||die("Encoding name is wrong");
$CharEncoding->SetToEncoding("UTF-8")||die("Encoding name is wrong");
echo $CharEncoding->EncodeString($s);
Use UTF-8 encoding to view in the browser, you will see the correct characters

Program download address:
http:/ /dreamcity2000.myetang.com/encoding.zip
When downloading, please reopen a browser window and enter the above address to download.
ps: If you want to reprint the program, please contact the author


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445220.htmlTechArticleA while ago I saw qiushuiwuhen Jun’s article about the conversion of gbk, unicode, big5, but there were some inaccuracies. It was a big problem, so I designed a class responsible for character conversion and corrected it...
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template