简繁 data_gb.php 下载,简繁转换的程序_php

php代码:--------------------------------------------------------------------------------

/**

*中速版,中等内存使用,使用于一般需求或有大量重复字的大段文本

*@text:待转换的字符串

http://www.gaodaima.com/45197.html简繁转换的程序_php

*@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

$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

$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;

}

/**

*高速版,最高内存使用,使用于大段文本时

*@text:待转换的字符串

*@table_file:转换映射表文件名

*/

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

$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;

}

?>

--------------------------------------------------------------------------------

欢迎大家阅读《简繁转换的程序_php》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码

原创文章,转载请注明: 转载自搞代码

e7ce419cf2d6ad34d01da2ceb8829eed.png

微信 赏一包辣条吧~

023a57327877fb4402bcc76911ec18ea.png

支付宝 赏一听可乐吧~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值