蜜桃无码视频,国产精品 17c,5g-天天看天天奭免费入口,乱亲女H秽乱长久久久

歡迎來到 常識詞典網(wǎng) , 一個專業(yè)的常識知識學習網(wǎng)站!

[ Ctrl + D 鍵 ]收藏本站

您所在的位置:首頁 > 電腦網(wǎng)絡 > 編程

編程

gb2312轉(zhuǎn)utf8的PHP代碼

分類: 編程 常識詞典 編輯 : 常識 發(fā)布 : 12-19

閱讀 :844

<?
//初始化gb2312--unicode數(shù)組對應表作為全程變量,以提高處理速度
$____global_codetable=array();
$____global_filename=pathinfo($_SERVER["SCRIPT_FILENAME"]);
$____global_filename=$____global_filename["dirname"]."/gb2312.txt";
$____global_tmp=file($____global_filename);
while(list($key,$value)=each($____global_tmp))
{
 if (strcmp($value{0},’#’)!=0)
 $____global_codetable[hexdec(substr($value,2,4))]=substr($value,9,4);
}
reset($____global_tmp);
while(list($key,$value)=each($____global_tmp))
{
 if (strcmp($value{0},’#’)!=0)
 $____global_codetable2[hexdec(substr($value,9,4))]=hexdec(substr($value,2,4));
}
unset($____global_filename);
unset($____global_tmp);


/*
將帶 &#x3F8F;&#x5354;格式的文本(可以包含其它ASCII字符)轉(zhuǎn)換成gb2312格式的文本;
可以用于XML編碼的轉(zhuǎn)換
需要注意的是,函數(shù)不改變xml中關于編碼的聲明
*/
function unicode2gb($un)
{
 if(!trim($un))
  return $un;
 $gb="";
 global $____global_codetable2;
 while(strlen($un)>0)
 {
  $p=strpos($un,"&#");
  if ($p===FALSE)//串中已無unicode字符
  {
   $gb.=$un;
   return $gb;
  }
  else
  {
   if ($p!=0)//串中unicode字符前綴不是第一個字符
   {
    $gb.=substr($un,0,$p);
    $un=substr($un,$p);
   }
   $p=strpos($un,";");
   if ($p===FALSE)//此前綴非unicode前綴,串中已無unicode字符
   {
         $gb.=$un;
         return $gb;
   }
   else
   {
    $code=substr($un,2,$p-2);
    $un=substr($un,$p+1);
    if (strcasecmp($code{0},"x")==0)//unicode碼16進制表示
    {
     $code=hexdec(substr($code,1));
    }else
    {
     $code=intval($code);
    }
           $code=0x8080|$____global_codetable2[$code];
    $gb.=chr((($code & 0xFF00)>>8) & 0xFF);
    $gb.=chr($code & 0xFF);
   }
  }
 }
 return $gb;
}

/*
將 gb2312格式的文本(可以包含其它ASCII字符)轉(zhuǎn)化為 帶 &#x3F8F;&#x5354;格式的unicode文本;
可以用于XML編碼的轉(zhuǎn)換
需要注意的是,函數(shù)不改變xml中關于編碼的聲明
*/
function gb2unicode($gb)
{
   if(!trim($gb))
      return $gb;
   $utf="";
   global $____global_codetable;
   while(strlen($gb)>0)
    {
     if (ord(substr($gb,0,1))>127)
        {
         $this=substr($gb,0,2);
         $gb=substr($gb,2);
         $code=$____global_codetable[hexdec(bin2hex($this))&0x7F7F];
         $utf.="&#x".$code.";";
        }
     else
        {
         $utf.=substr($gb,0,1);
         $gb=substr($gb,1);
        }
     }
   return $utf;
}

/*
將utf8格式的文本轉(zhuǎn)化為gb2312格式的文本;這與上述的unicode2gb不同,是二進制格式的轉(zhuǎn)換
*/
function utf82gb($utf8)
{
   if(!trim($utf8))
      return $utf8;
   global $____global_codetable2;
   $gb="";
   while(strlen($utf8)>0)
    {
 $c=substr($utf8,0,1);
 $d=ord($c);
 if (($d&0x80) == 0)//1位
 {
  $gb.=$c;
  $utf8=substr($utf8,1);
 }
 else
 if (($d&0xC0)==0x80)//錯位
 {
  $utf8=substr($utf8,1);
 }
 else
 if (($d&0xE0)==0xC0)//2位
 {
  $utf8=substr($utf8,2);
 }
 else
 if (($d&0xF0)==0xE0)//3位
 {
  $d1=ord($utf8{1}) & 0x3F;
  $d2=ord($utf8{2}) & 0x3F;
  $d=$d & 0x0F;
  $d=($d<<12) + ($d1 <<6) + $d2;
         $code=0x8080|$____global_codetable2[$d];
  $gb.=chr((($code & 0xFF00)>>8) & 0xFF);
  $gb.=chr($code & 0xFF);
  $utf8=substr($utf8,3);
 }
 else
 if (($d&0xF8)==0xF0)//4位
 {
  $d1=ord($utf8{1}) & 0x3F;
  $d2=ord($utf8{2}) & 0x3F;
  $d3=ord($utf8{3}) & 0x3F;
  $d=$d & 0x07;
  $d=($d<<18) + ($d1 <<12) + ($d2 << 6) +$d3;
  //$code=0x8080+getgb($d);
         $code=0x8080|$____global_codetable2[$d];
  $gb.=chr((($code & 0xFF00)>>8) & 0xFF);
  $gb.=chr($code & 0xFF);
  $utf8=substr($utf8,4);
 }
 else
 {
  $utf8=substr($utf8,1);
 }
    }
   return $gb;
}

/*
將gb2312格式的文本轉(zhuǎn)化為utf8格式的文本;這與上述的gb2unicode不同,是二進制格式的轉(zhuǎn)換
*/
function gb2utf8($gb)
{
   if(!trim($gb))
      return $gb;
   global $____global_codetable;
   $utf8="";
   while(strlen($gb)>0)
   {
 if (ord(substr($gb,0,1))>127)
 {
         $code=substr($gb,0,2);
         $gb=substr($gb,2);
         //echo "gb=$code;";
         $code=bin2hex($code);
         //echo "code=$code;";
         $code=hexdec($code)&0x7F7F;
         //echo "newcode=".dechex($code);
         $code=$____global_codetable[$code];
         //echo "unicode=$code";
         $code=hexdec($code);
         //11位:6+5
         if (($code&0x7FF)==$code)
         {
          $utf8.=chr(0xC0|((($code&0x7C0)>>6)&0x3F));
          $utf8.=chr(0x80|($code&0x3F));
         }else
         //16位:12+4
         if (($code&0xFFFF)==$code)
         {
          $utf8.=chr(0xE0|((($code&0xF000)>>12)&0x3F));
          $utf8.=chr(0x80|((($code&0xFC0)>>6)&0x3F));
          $utf8.=chr(0x80|($code&0x3F));
          //echo "16位==$utf8;\n";
         }
         else
         //21位:18+3
         if (($code&0x1FFFFF)==$code)
         {
          $utf8.=chr(0xF0|((($code&0x1C0000)>>18)&0x3F));
          $utf8.=chr(0x80|((($code&0x3F000)>>12)&0x3F));
          $utf8.=chr(0x80|((($code&0xFC0)>>6)&0x3F));
          $utf8.=chr(0x80|($code&0x3F));
         }
         /*
         else
         //26位:24+2
         if (($code&0x3FFFFFF)==$code)
         {
          $utf8.=chr(0xF8|((($code&0x3000000)>>24)&0x3F));
          $utf8.=chr(0x80|((($code&0xFC0000)>>18)&0x3F));
          $utf8.=chr(0x80|((($code&0x3F000)>>12)&0x3F));
          $utf8.=chr(0x80|((($code&0xFC0)>>6)&0x3F));
          $utf8.=chr(0x80|($code&0x3F));
         }
         else
         //31位:30+1
         if (($code&0x7FFFFFFF)==$code)
         {
          $utf8.=chr(0xFC|((($code&0x40000000)>>30)&0x3F));
          $utf8.=chr(0x80|((($code&0x3F000000)>>24)&0x3F));
          $utf8.=chr(0x80|((($code&0xFC0000)>>18)&0x3F));
          $utf8.=chr(0x80|((($code&0x3F000)>>12)&0x3F));
          $utf8.=chr(0x80|((($code&0xFC0)>>6)&0x3F));
          $utf8.=chr(0x80|($code&0x3F));
         }
         //36位
         else
         {
          //首字節(jié)全部作為前綴,無數(shù)據(jù)
          $utf8.=chr(0x80|((($code&0xC0000000)>>30)&0x3F));
          $utf8.=chr(0x80|((($code&0x3F000000)>>24)&0x3F));
          $utf8.=chr(0x80|((($code&0xFC0000)>>18)&0x3F));
          $utf8.=chr(0x80|((($code&0x3F000)>>12)&0x3F));
          $utf8.=chr(0x80|((($code&0xFC0)>>6)&0x3F));
          $utf8.=chr(0x80|($code&0x3F));
         }
         */
 }
 else
 {
  $utf8.=substr($gb,0,1);
  $gb=substr($gb,1);
 }
  }
  return $utf8;
}
?>

下一篇:怎么成長為一名黑客 下一篇 【方向鍵 ( → )下一篇】

上一篇:怎樣漢化GBA游戲 上一篇 【方向鍵 ( ← )上一篇】

中文字幕av干| 日本高潮A级中文片免费| av一级福利| 国产精品最新免费视频| www。777| 伊在人天堂亚洲香蕉精品区| 国产黄色视频一区二区三区四区| 玩弄美女人妻少妇视频| 毛片视频免费人成观看| 成人在线视频18| 精品综合欧美一区二区三区| 神马我不卡久色| 久久伊人图片一区| 新久久毛片| 中文字幕制服丝袜在线播放| 国产精品白浆| 久久精品亚洲aⅤ无码| 久久精品国产剧| 国产欧美一区二区精品久久久| 99久久韩国精品二区| 五十路六十路熟妇中出| 一本一本久久A久久综合精品蜜桃| 成人2020综合网| 亚洲AV无码风间由美| 五月丁香五月综合| 欧美视频免费一区二区三区| 久久无码人妻一区二区抖音| 久久性爱片区| 久久人人做人人妻人人玩精品VA| 女人高潮被爽到呻吟在线观看 | 中文字幕在线无码不卡网址| 无码成人小说| 亚洲AV无码成人精品| 国产在线观看无遮挡| 高潮潮喷奶水飞溅视频无码| 2020年理论片| 人妻久久精品一区二区夜夜嗨| 国产自无码视频在线观看手机| 爆乳中文字幕| 亚洲精品无码专区不卡| 国厂精品46区一区|