织梦之GB码转换成Big5码
2024-08-30 19:06:35
供稿:网友
/********************************
//gb码转换成big5码
*********************************/
function gb2big5($text) {
global $gb_data;
if(empty($gb_data)){
$filename = dirname(__file__)."/data/gb-big5.table";
$fp = fopen($filename, "rb");
$gb = fread($fp,filesize($filename));
fclose($fp);
}
$max = strlen($text)-1;
for($i=0;$i<$max;$i++) {
$h = ord($text[$i]);
if($h>=0x80) {
$l = ord($text[$i+1]);
if($h==161 && $l==64) {
$big = " ";
}else{
$p = ($h-160)*510+($l-1)*2;
$big = $gb_data[$p].$gb_data[$p+1];
}
$text[$i] = $big[0];
$text[$i+1] = $big[1];
$i++;
}
}
return $text;
}