Simple and traditional conversion program. PHP code :--------------------------------------------------------------------------------? Php *** medium speed version, medium memory usage, used in a large PHP code segment with a general requirement or a large number of repeated words :--------------------------------------------------------------------------------
/**
* Medium speed edition, medium memory usage, used for large text segments that generally require or have a large number of repeated words
* @ Text: string to be converted
* @ Table_file: name of the conversion ing table file
*/
Function encode_trans1 ($ text, $ table_file = 'gb2big5 '){
$ Fp = fopen ($ table_file. '. table', "r ");
$ Cache = array ();
$ Max = strlen ($ text)-1;
For ($ I = 0; $ I <$ max; $ I ++ ){
$ H = ord ($ text [$ I]);
If ($ h> = 160 ){
$ L = ord ($ text [$ I + 1]);
If ($ h = 161 & $ l = 64 ){
$ Text [$ I] = "";
} Else {
$ Cut = substr ($ text, $ I, 2 );
If (! $ Cache [$ cut]) {
Fseek ($ fp, ($ h-160) * 510 + ($ L-1) * 2 );
$ Cache [$ cut] = fread ($ fp, 2 );
}
$ Text [$ I] = $ cache [$ cut] [0];
$ Text [++ $ I] = $ cache [$ cut] [1];
}
}
}
Fclose ($ fp );
Return $ text;
}
/**
* Low-speed version, with the lowest memory usage, when using a few characters
* @ Text: string to be converted
* @ Table_file: name of the conversion ing table file
*/
Function encode_trans2 ($ text, $ table_file = 'gb2big5 '){
$ Fp = fopen ($ table_file. '. table', "r ");
$ Max = strlen ($ text)-1;
For ($ I = 0; $ I <$ max; $ I ++ ){
$ H = ord ($ text [$ I]);
If ($ h> = 160 ){
$ L = ord ($ text [$ I + 1]);
If ($ h = 161 & $ l = 64 ){
$ Gb = "";
} Else {
Fseek ($ fp, ($ h-160) * 510 + ($ L-1) * 2 );
$ Gb = fread ($ fp, 2 );
}
$ Text [$ I] = $ gb [0];
$ Text [$ I + 1] = $ gb [1]; $ I ++;
}
}
Fclose ($ fp );
Return $ text;
}
/**
* High-speed edition with maximum memory usage, used for large text segments
:--------------------------------------------------------------------------------? Php/*** medium speed edition, medium memory usage, used in large segments with general requirements or a large number of repeated words...