Php Chinese character conversion: Unicode (UTF8) to GBK_PHP tutorial

Source: Internet
Author: User
Tags php download
Conversion of php Chinese characters: Unicode (UTF8) to GBK. P. Qiushui no hate GBKUnicodeUTF8 Chinese character conversion php's Chinese character conversion has always been quite troublesome. This class has four built-in filters # [dec];, # x [hex];, % u [hex], utf8 conversion is convenient for users. at the same time, P> Qiu Shui does not hate GBK Unicode UTF8 Chinese character conversion
Converting Chinese characters in php has always been a problem.
This class has four built-in filters "& # [dec];", "& # x [hex];", "% u [hex]", "utf8 conversion"
It is convenient for users and supports custom filtering for their favorite operations.
QswhU. php download from here
Http://www.blueidea.com/user/qswh/qswhU.zip
Class qswhU {
Var $ qswhData;
Function qswhU ($ filename = "qswhU. php "){
$ This-> qswhData = file ($ filename );
}

Function decode ($ str, $ pattern = 0 ){
$ Arr = array ("/& # (w +);/iU", "/(% ww) +)/I ", "/% u (w {4, 5})/iU ");
If (is_integer ($ pattern )){
If ($ pattern> = count ($ arr) die ("Invalid Function ");
$ Pattern = $ arr [$ pattern];
}
Return preg_replace_callback ($ pattern, array ($ this, "u2gb"), $ str );
}

Function u2gb ($ arr ){
/***** (Qiushuiwuhen 2002-8-15 )******/
$ Ret = ""; $ str = $ arr [1];
If (preg_match_all ("/% w {2}/", $ str, $ matches )){
For ($ I = 0; $ I $ Chr1 = hexdec (substr ($ matches [0] [$ I], 1 ));
$ Arr = array ("f0", "e0", "c0", "0 ");
For ($ j = 0; $ j Hexdec ($ arr [$ j]) break;
$ Chr = hexdec (substr ($ matches [0] [$ I], 1)-hexdec ($ arr [$ j]);
While (++ $ j $ Str = dechex ($ chr );
If (strlen ($ str) = 4 ){
$ P = hexdec (substr ($ str, 0, 2)-0x4d;
$ Q = hexdec (substr ($ str, 2) * 4;

GBK Unicode UTF8 Chinese character conversion php Chinese character conversion has always been quite troublesome. This class has four built-in filters # [dec];, # x [hex];, % u [hex], utf8 conversion is convenient for users...

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.