PHP's Chinese character conversion has always been more troublesome. First of all, it is necessary to say two points: 1.GBK's traditional word is not BIG5, but general traditional characters have corresponding BIG code 2. A GBK code does not necessarily have a corresponding BIG5 code. So generally irreversible conversion
This class has a built-in QSWHSTR formatted string qswhfile formatted a file QSWHDIR formatted all files in the directory (except for. QSWH, it is the backup of the original document)
QSWHBIG5.PHP 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 127) {$ = ORD (Substr ($ GB, $ I, 1)); $ TMP = $ THIS-> QSWHDATA [ $ P-128]; for ($ J = 0; $ J = $ Q) Break; if ($ k == $) $ = CHR (HEXDEC (Substr ($ TMP, $ J 2, 2)))). Chr (HEXDEC (Substr ($ TMP, $ J 4, 2 ))))); ELSE IF ($ FAIL == ") $ Q = CHR ($ P) .chr ($ Q); Else $ = $ FAIL;} else $ = CHR ($ P); $ RET. = $} Return $ RET;} Function Qswhfile ($ filename, $ fund = "??") {/ ****** (Qiushuiwuhen 2002-9-6) ****** / if (! File_exists ($ FileName)) Copy ($ FileName, $ FileName. ". qswh"); $ fp = fopen ($ FileName, "R "); $ TMP = FREAD ($ FP, FileSize) )); Rewind ($ fp); fwrite ($ fp, $ 10-> QSWHSTR ($ TMP, $ FAIL)); fclose ($ fp);} Function Qswhdir ($ DIRNAME, $ FAIL = "??") { / ****** (Qiushuiwuhen 2002-9-6) ****** / $ d = DIR ($ dirname); while ($ entry = $ d-> read ()) {if ($ entry == "." | $ entry == ".") Continue; $ entry = $ dirname. "/". $ entry; Is_dir ($ entry)) $ this-> qswhdir ($ Entry, $ fail); Else {IF (Substr ($ ENTRY, -5)! = ". qswh") $ this-> qswhfile ($ Entry, $ FAIL) }}} $ D-> close (); return $ c;}} Example: $ Words = "Qiu Water no hate"; $ qswh = new qswhbig5 ("qswhbig5.php"); // qswhbig5.php, province parameter
Echo ("
Select the encoded BIG5 View:" $ qsWh-> qswhstr ($ word)); echo ("/ N encoding a directory:". $ qsWh-> qswhdir ("test"); echo "/ n encoding one file:" $ qswh-> qswhfile ("index.htm")); use instructions: qswhstr Representative Represents the word in QSWHSTR If there is no corresponding BIG5 will replace the word, if it is empty, keep it After the word will format the file, remember to modify the content-type in
PS. This article is now limited to the 9CBS document center, for example to reprint, please contact the author, otherwise the consequences are at your own risk.