Discuz!官方免费开源建站系统

 找回密码
 立即注册
搜索

[转换] 求简繁转换映射表文件

[复制链接]
codylee 发表于 2007-9-19 00:42:37 | 显示全部楼层 |阅读模式
我在百度和google搜索了很久,发现都是提供转换程序,就唯独缺少换映射表文件,那位大侠有,能否提供一下,小弟万分感谢!

  1. <?php
  2. <?php
  3. /**
  4. *中速版,中等内存使用,使用于一般需求或有大量重复字的大段文本
  5. *@text:待转换的字符串
  6. *@table_file:转换映射表文件名
  7. */
  8. function encode_trans1($text,$table_file='gb2big5') {
  9.     $fp = fopen($table_file.'.table', "r");
  10.     $cache = array();
  11.     $max=strlen($text)-1;
  12.     for($i=0;$i<$max;$i++) {
  13.         $h=ord($text[$i]);
  14.         if($h>=160) {
  15.             $l=ord($text[$i+1]);
  16.             if($h==161 && $l==64) {
  17.                 $text[$i]=" ";
  18.             } else{
  19.                 $cut = substr($text,$i,2);
  20.                 if(!$cache[$cut]) {
  21.                     fseek($fp,($h-160)*510+($l-1)*2);
  22.                     $cache[$cut] = fread($fp,2);
  23.                 }
  24.                 $text[$i] = $cache[$cut][0];
  25.                 $text[++$i] = $cache[$cut][1];
  26.             }
  27.         }
  28.     }
  29.     fclose($fp);
  30.     return $text;
  31. }

  32. /**
  33. *低速版,最低内存使用,使用于少量字符时
  34. *@text:待转换的字符串
  35. *@table_file:转换映射表文件名
  36. */
  37. function encode_trans2($text,$table_file='gb2big5') {
  38.     $fp = fopen($table_file.'.table', "r");
  39.     $max=strlen($text)-1;
  40.     for($i=0;$i<$max;$i++) {
  41.         $h=ord($text[$i]);
  42.         if($h>=160) {
  43.             $l=ord($text[$i+1]);
  44.             if($h==161 && $l==64) {
  45.                 $gb=" ";
  46.             }else{
  47.                 fseek($fp,($h-160)*510+($l-1)*2);
  48.                 $gb=fread($fp,2);
  49.             }
  50.             $text[$i]=$gb[0];
  51.             $text[$i+1]=$gb[1]; $i++;
  52.             }
  53.         }
  54.     fclose($fp);
  55.     return $text;
  56. }
  57. /**
  58. *高速版,最高内存使用,使用于大段文本时
  59. *@text:待转换的字符串
  60. *@table_file:转换映射表文件名
  61. */
  62. function encode_trans3($text,$table_file='gb2big5') {
  63.     $fp = fopen($table_file.'.table', "r");
  64.     $str = fread($fp,strlen($table_file.'.table'));
  65.     fclose($fp);
  66.     $max=strlen($text)-1;
  67.     for($i=0;$i<$max;$i++) {
  68.         $h=ord($text[$i]);
  69.         if($h>=160) {
  70.             $l=ord($text[$i+1]);
  71.             if($h==161 && $l==64) {
  72.                 $text[$i]=' ';
  73.                 $text[++$i]=' ';
  74.             }else{
  75.                 $pos = ($h-160)*510+($l-1)*2;
  76.                 $text[$i]=$str[$pos];
  77.                 $text[++$i]=$str[$pos+1];
  78.             }
  79.         }
  80.     }
  81.     return $text;
  82. }
  83. ?>
  84. ?>
复制代码
回复

使用道具 举报

 楼主| codylee 发表于 2007-9-19 11:37:18 | 显示全部楼层
哪位大哥有?
回复

使用道具 举报

 楼主| codylee 发表于 2007-9-20 09:45:09 | 显示全部楼层
全世界都没有人有了!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2025-9-13 18:32 , Processed in 0.103881 second(s), 14 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表