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...