Home  >  Article  >  php教程  >  织梦之GB码转换成Big5码

织梦之GB码转换成Big5码

WBOY
WBOYOriginal
2016-06-21 08:58:10897browse

转换

/********************************
//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  $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;
}



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn