This article mainly introduces the PHP implementation of various Chinese encoding conversion class sharing, this class library supports the conversion between Simplified Chinese, Traditional Chinese, GB2312, BIG5, UTF-8 and other formats, you can refer to the current class libraries for encoding conversion: Simplified Chinese GB <-> Traditional Chinese BIG5 encoding interchange, simple/traditional Chinese-> Pinyin one-way conversion, simplified/traditional Chinese <-> UTF8 encoding conversion, simplified/traditional Chinese-> Unicode one-way conversion.
The original author of the class source code is Hessian (solarischan@21cn.com), I merged the original Sample script, and modified the class file, add a parameter to the class constructor so that you can easily set the configuration file path when using it. in this way, you can place this class package in any directory that can be accessed, otherwise, the original version references class. chinese. php files and classes must be in the same directory.
The code is as follows:
/**
* Chinese encoding set class library
*
* Currently, this class library can be used for conversion between Simplified Chinese and traditional Chinese <-> Traditional Chinese encoding, simplified Chinese and traditional Chinese-> Pinyin one-way conversion,
* Simplified Chinese and traditional Chinese <-> UTF8 encoding conversion, simplified Chinese and traditional Chinese-> Unicode one-way conversion
*
* @ Author Hessian (solarischan@21cn.com)
* @ Version 1.7
* @ Copyright: Hessian/NETiS
* @ Use authorized GPL (the code cannot be used for any commercial purposes and can be modified without the author's consent, but the modified code must be published in accordance with the GPL protocol)
* @ Special thanks to unknow (simplified conversion code snippet)
* @ Start
* @ Last modification
* @ Access public
*
* Update records
*
* Ver 1.7
* The bug caused by the while loop is modified. This bug will handle errors when the last character of the string is "0.
* Affected methods: CHStoUTF8 (), CHStoUNICODE ()
* (By Zeal Li, http://www.zeali.net /)
*
* Ver 1.6
* The constructor adds a parameter so that you can conveniently set the configuration file path when using it.
* (By Zeal Li, http://www.zeali.net /)
*
* Ver 1.5
* Added the UTF8 conversion function to GB2312 and BIG5.
*
* Ver 1.4
* The value of charset can be changed if the value is set to true when HTML is converted.
*
* Ver 1.3
* The function of converting traditional Chinese to pinyin is added.
*
* Ver 1.2
* Merge functions that convert simplified and traditional Chinese to UTF8.
* The function for converting Simplified Chinese to pinyin. The return value is changed to a string. the pinyin of each Chinese character is separated by spaces.
* Supports converting Simplified Chinese to UNICODE.
* The function of converting traditional Chinese to UNICODE is added.
*
* Ver 1.1
* Added the OpenFile () function to support opening local files and remote files.
* Added the function of converting Simplified Chinese to UTF8.
* The function of converting traditional Chinese to UTF8 is added.
*
* Ver 1.0
* A class library integrating simplified Chinese characters and traditional Chinese characters corresponding to various encoding interchange has been initially completed.
*/
Download the full source code package (filesize: 132,522 bytes): download the source code chinese.rar