Some time ago I saw qiushuiwuhen Jun's article on gbk, unicode, and big5 conversion, but there were some minor problems, so I designed a class responsible for character conversion, corrected some of the shortcomings and added some features. in the future, I will continue to expand the class to support more character sets by adding the following points: conversion of unicode-gbk symbols a while ago I saw qiushuiwuhen's article about gbk, unicode, and big5 conversion.
However, there are some minor problems.
So I designed a class responsible for character conversion, corrected some of the shortcomings, and added some features. in the future, I will continue to expand this class to support more character sets.
The following points are added:
Unicode-> gbk symbol part conversion
Identification of euro characters (€)
Big5, Unicode, and GBK are mutually converted, provided that only the common character set 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)
Function parameters can only be encoded using the preceding five encoding methods, which are case-sensitive. for example, GBK cannot be written as gbk.
If the setting is successful, true is returned. If an incorrect encoding name is used, false is returned, and the actual error message is returned.
Function
String EncodeString (string $ String)
Responsible for character encoding conversion and returning the converted string
Before use, set the var $ FilePath = "" variable to the absolute path of the program file. Otherwise, the data file cannot be found.
Example:
Convert a gbk encoded string to a UTF-8 encoding:
$ S = "GBK encoding ";
$ CharEncoding = new Encoding ();
$ CharEncoding-> SetGetEncoding ("GBK") | die ("incorrect encoding name ");
$ CharEncoding-> SetToEncoding ("UTF-8") | die ("encoding name error ");
Echo $ CharEncoding-> EncodeString ($ s );
Use UTF-8 encoding in your browser to see the correct characters
Program:
Http://dreamcity2000.myetang.com/encoding.zip
When downloading, open a new browser window and enter the above address to download it.
Ps: If the program is to be reproduced, please contact the author