PHP's character encoding conversion tool

Source: Internet
Author: User
Tags character set
A while ago, I saw Qiushuiwuhen June's article on Gbk,unicode,big5 's conversion.
But there are a few less big problems
So I designed a class that is responsible for character conversion, fixed some of these deficiencies, added some features, and I will continue to expand the class to support more character sets
Added the following points:
Conversion of UNICODE->GBK symbol parts
Identification of the euro character (€)
Conversion between BIG5,UNICODE,GBK, provided that only the common character set part is converted,
Instructions for use:
Temporary programs support 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 mode is GBK, and the default output encoding is UTF-16BE;
This category provides two functions to modify the input and output encoding methods:
Modify Input Encoding Boolean setgetencoding (String $GetEncoding)
Modify Output Encoding Boolean settoencoding (String $ToEncoding)
function parameters can only be used in the above 5 encoding methods, case-sensitive, such as GBK can not be written GBK
Returns true if the setting succeeds, returns False if the wrong encoding name is used, and the actual error message
Function
String encodestring (String $String)
Responsible for character encoding conversion, returning the converted string
Before using, convert the var $FilePath = "" Variable to the absolute path of the program file, or you will not find the data file
Example:
Converts a GBK encoded string to a UTF-8 encoding:
$s = "GBK encoding";
$CharEncoding =new Encoding ();
$CharEncoding->setgetencoding ("GBK") | | Die ("Coding name error");
$CharEncoding->settoencoding ("UTF-8") | | Die ("Coding name error");
Echo $CharEncoding->encodestring ($s);
Using 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 address above to download.
PS: If the program to reprint, please contact the author

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.