(注:源代碼中的include "data_gb.php";這個文件在就是一個數組,在http://caocao.oso.com.cn/data_gb.zip,請編輯下載到oso上,做一個鏈接, " /> 国产精品毛片久久久,久久99日本精品,3751色影院一区二区三区

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

簡體中文轉換為繁體中文的PHP函數

感謝網友Keyes提供移植用的Delphi源代碼。其調用方式為$txt=gbtobig5($txt)。
    (注:源代碼中的include "data_gb.php";這個文件在就是一個數組,在http://caocao.oso.com.cn/data_gb.zip,請編輯下載到oso上,做一個鏈接,因為這個文件我過幾天就要刪除了。)

<?
/***********************************************************************
                       Written by caocao
                       caocao@eastday.com
                       http://caocao.oso.com.cn

                       With the help of Keyes
                       Keyes2000@263.NET
                       http://my-wjl.scu.edu.cn/~Keyes
***********************************************************************/
function isgb($code)
{
  if (strlen($code)>=2)
  {
    $code=strtok($code,"");
    if ((ord($code[0]) < 161)||(ord($code[0]) >= 247))
    {
      return (0);
    }
    else
    {
      if ((ord($code[1]) <= 161)||(ord($code[1]) >= 254))
      {
        return (0);
      }
      else
      {
        return (1);
      }
    }
  }
  else
  {
    return (1);
  }
}

function gboffset($code)
{
  if (strlen($code) >= 2)
  {
    $code=strtok($code,"");
    return ((ord($code[0]) - 161) * 94 + (ord($code[1]) - 161));
  }
  else
  {
    return(-1);
  }
}

function wordtostring($code)
{
  return (chr(hexdec(substr($code,0,2))).chr(hexdec(substr($code,2,2))));
}

function gbtobig5($code)
{
  include "data_gb.php";
  $output="";
  $length=strlen($code);
  $code=strtok($code,"");
  $idx=0;
  while ($idx < $length)
  {
    $tmpStr=$code[$idx].$code[$idx+1];

    if (isgb($tmpStr))
    {
      $offset=gboffset($tmpStr);
      if (($offset >= 0)||($offset <= 8177))
      {
        $output.=wordtostring($gborder[$offset]);
        $idx++;
      }
      else
      {
        $output.= $code[$idx];
      }
    }
    else
    {
      $output.= $code[$idx];
    }
    $idx++;
  }
  return ($output);
};
?>  

【本文版權歸作者與奧索網共同擁有,如需轉載,請注明作者及出處】    

php技術簡體中文轉換為繁體中文的PHP函數,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 剑河县| 佛坪县| 罗源县| 仁寿县| 青海省| 积石山| 那曲县| 西平县| 伽师县| 沅陵县| 湄潭县| 南城县| 田林县| 中西区| 嘉禾县| 榆林市| 轮台县| 井研县| 永平县| 施甸县| 汕尾市| 锦州市| 鄂托克前旗| 泽库县| 竹溪县| 延吉市| 藁城市| 辽源市| 井研县| 巴林左旗| 涟源市| 吉木萨尔县| 德清县| 砚山县| 外汇| 泽普县| 惠东县| 海南省| 岱山县| 东乡| 甘孜县|