快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

简繁转变的程序

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;
}
?>

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







返回类别: 教程
上一教程: PHP编码规范
下一教程: Apache的httpd.conf文件常用指令解释

您可以阅读与"简繁转变的程序"相关的教程:
· php写的发送附件的程序(一)
· 用PHP实现banner轮换的程序代码
· 不用GD库生成当前时间的PNG格式图象的程序
· 写一个用户在线显示的程序
· 不用GD库生成当前时间的PNG格式图象的程序
    微笑服务 优质保证 索取样品