终于实现简体转繁体,繁体到转体
时间:2007-02-18 来源:PHP爱好者
代码如下:
CODE:
[复制到剪切板]
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>";
} php爱好者站 http://www.phpfans.net PHP|MySQL|javascript|ajax|html.
心得体会:其实简体->繁体 繁体->简体 的过程是一样的,只是使用的对应表不同,我一开始是被网页上输出来的字所误会了,其实是已经转换的了,看输出后的html代码就知道,害我浪费了那么多的时间,但搞出来心里还是很高兴
$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>";
} php爱好者站 http://www.phpfans.net PHP|MySQL|javascript|ajax|html.
心得体会:其实简体->繁体 繁体->简体 的过程是一样的,只是使用的对应表不同,我一开始是被网页上输出来的字所误会了,其实是已经转换的了,看输出后的html代码就知道,害我浪费了那么多的时间,但搞出来心里还是很高兴
相关阅读 更多 +