The program of simple multiplication conversion
Last Update:2017-02-28
Source: Internet
Author: User
program | Simplified conversion PHP Code:--------------------------------------------------------------------------------
<?php
/**
* Medium-speed version, medium memory use, use for general requirements or large text with a large number of repeated words
* @text: strings to be converted
* @table_file: Converting the mapping Table file name
*/
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, minimum memory use, for a small number of characters characters
* @text: strings to be converted
* @table_file: Converting the mapping Table file name
*/
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 version, maximum memory usage, when used for large segment text
* @text: strings to be converted
* @table_file: Converting the mapping Table file name
*/
function Encode_trans3 ($text, $table _file= ' Gb2big5 ') {
$fp = fopen ($table _file. Table ', "R");
$str = Fread ($fp, strlen ($table _file). Table '));
Fclose ($FP);
$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]= ';
$text [+ + $i]= ';
}else{
$pos = ($h -160) *510+ ($l-1) *2;
$text [$i]= $str [$pos];
$text [+ + $i]= $str [$pos +1];
}
}
}
return $text;
}
?>
--------------------------------------------------------------------------------