php簡繁體轉換

来源:互联网 发布:js慕课网 编辑:程序博客网 时间:2024/05/18 17:01
实现简体转繁体,繁体到转体
2007-12-27 16:34

function gb2big5($Text){   
   
$fp fopen("gb-big5.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
;  

/**************简体转繁体 end******************/

/**************繁体转简体 start******************/
function big52gb($Text
){
   
$fp fopen("big5-gb.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
;
   }
/**************繁体转简体 end******************/

测试:

if(isset($_POST["rrff"
])){

echo 
"<a href=big2togb.php>back</a><br>"
;
echo 
big52gb($_POST[a
]);
if(
$query) echo "OK"
;

}
else {
echo 
"<meta http-equiv=Content-Type content=text/html; charset=big5>"
;
echo 
"<form action="big2togb.php" method="post">"
;
echo 
"<textarea name=a cols=80 rows=20></textarea>"
;
echo 
"<input type=submit name=rrff value=big5-gb>"
;
echo 
"</form>"
;
}

以上内容来自 http://www.it596.com/(程序员的技术讨论与分享园地)

原创粉丝点击