最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
简繁转换的程序
时间:2008-01-11 编辑:简简单单 来源:一聚教程网
/**
*中速版,中等内存使用,使用于一般需求或有大量重复字的大段文本
*@text:待转换的字符串
*@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;
}
/**
*低速版,最低内存使用,使用于少量字符时
*@text:待转换的字符串
*@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;
}
/**
*高速版,最高内存使用,使用于大段文本时
-
上一个: 获得客户端真实的IP地址
-
下一个: 哈,怎么跑到这里来问了?进来看
相关文章
- Java中两位年份的转化程序代码 09-24
- 求伯君20年跌宕起伏:最牛程序员华丽转身 05-06
- 从程序员到系统分析员(转) 01-12
- 一个新版本的ubb转化程序 01-12
- 程序员的七种武器(转) 01-12
- 国外站点上转过来的资料,模拟ping程序 01-12