一段PHP代码,将繁体转简体的代码怎么用

来源:百度知道 编辑:UC知道 时间:2024/07/07 04:13:10
<?php
/**
*高速版,最高内存使用,使用于大段文本时
*@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
if($_GET['a'] == "f2j")
$content = encode_trans3($_POST['content']);
?>
<form action="?a=f2j" method="post">
<textarea name="content" cols="80" rows="5">
<?php echo $content; ?>
</textarea>
<br />
<input type="submit" value="繁 to 简" />
</form>