Php character encoding and conversion tool

Source: Internet
Author: User
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

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.