您现在的位置:中国下载站学院中心网络编程PHP教程PHP实例教程 → 文章列表

简繁转换的程序

作者:佚名  来源:不详  发布时间:2006-12-29 11:09:14   

减小字体 增大字体

 
 
PHP代码:--------------------------------------------------------------------------------

<?php
/**
*中速版,中等内存使用,使用于一般需求或有大量重复字的大段文本
*@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;
}
/**
*高速版,最高内存使用,使用于大段文本时
*@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<$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;
}
?>

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



字体 】【itbulo.com/index.asp?boardid=51" title="如有错误,麻烦请及时告诉我们。谢谢。">报告错误】【itbulo.com/">进入软件交流区】【关闭

在百度中搜索更多简繁转换的程序相关网页 转贴于:中国下载站

  • 上一篇文章:php.ini中文版
  • 下一篇文章:JSP学习笔记(九)-----JSP标签库
  • 阅读统计:[]
  • 中国下载站】【设为主页】【收藏本页】【打印本文】【回到顶部】【关闭此页

    相关文章
    文章评论(评论内容只代表网友观点,与本站立场无关!)

    用户名: 查看更多评论

    分 值:100分 85分 70分 55分 40分 25分 10分 0分

    内 容:

             (注“”为必填内容。) 验证码: 验证码,看不清楚?请点击刷新验证码


    设为首页 - 关于我们 - 广告服务 - 网站地图 - 加入收藏 - 网站声明 - 网站帮助 - 友情链接

    • Copyright (C) 2006-2008 www.cndownz.com All Rights Reserved.
      中国下载站 版权所有. 粤ICP备05141802号. 对本站有任何建议、意见或投诉,请来信:cndownzcom@yahoo.com.cn.
      喜欢中国下载站(cndownz.com),请把中国下载站(cndownz.com)告诉你QQ上的5位好友,多谢支持!