Conversion of php Chinese characters: GBK to Big5. Pphp's conversion of Chinese characters has always been quite troublesome. First, we should say two points: 1. the traditional Chinese version of GBK is not Big5, but generally the traditional Chinese version has a corresponding Big Code 2. a gbk code does not necessarily have a corresponding Big5 code P> Chinese character conversion in php has always been a hassle
There are two points:
1. GBK traditional Chinese characters are not Big5, but generally traditional Chinese characters have Big codes.
2. a GBK code does not necessarily have a corresponding Big5 code, so it is generally irreversible conversion.
This class has three built-in functions.
QswhStr format string
QswhFile format a file
QswhDir format all files in the Directory (except for. qswh, which is the backup of the original document)
QswhBig5.php download from here
Http://www.blueidea.com/user/qswh/qswhBig5.zip
Class qswhBig5 {
Var $ qswhData;
Function qswhBig5 ($ filename = "qswhBig5.php "){
$ This-> qswhData = file ($ filename );
}
Function qswhStr ($ gb, $ fail = "?? "){
/***** (Qiushuiwuhen 2002-9-6 )******/
$ Ret = "";
For ($ I = 0; $ I If ($ p = ord (substr ($ gb, $ I, 1)> 127 ){
$ Q = ord (substr ($ gb, ++ $ I, 1 ));
$ Tmp = $ this-> qswhData [$ p-128];
For ($ j = 0; $ j = $ Q) break;
If ($ k = $ q) $ q = chr (hexdec (substr ($ tmp, $ j + 2, 2 ))). chr (hexdec (substr ($ tmp, $ j + 4, 2 )));
Else if ($ fail = "") $ q = chr ($ p). chr ($ q); else $ q = $ fail;
}
Else
$ Q = chr ($ p );
$ Ret. = $ q;
}
Return $ ret;
}
Function qswhFile ($ filename, $ fail = "?? "){
/***** (Qiushuiwuhen 2002-9-6 )******/
If (! File_exists ($ filename. ". qswh") copy ($ filename, $ filename. ". qswh ");
$ Fp = fopen ($ filename, "r + ");
$ Tmp = fread ($ fp, filesize ($ filename ));
Rewind ($ fp );
Fwrite ($ fp, $ this-> qswhStr ($ tmp, $ fail ));
Fclose ($ fp );
}
First, let's talk about two points: 1. the traditional Chinese characters of GBK are not Big5, but generally the traditional Chinese characters have the corresponding Big Code. 2. a GBK code does not necessarily have the corresponding Big5 code...