首頁  >  文章  >  後端開發  >  繁體中文 繁體中文轉換為簡體中文的PHP函數

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

WBOY
WBOY原創
2016-07-29 08:34:191130瀏覽

前幾天我在oso論壇上問有沒有這個來源程序,沒人回覆。終於下定決心移植一個這樣的函數,感謝網友Keyes提供移植用的Delphi原始碼。其呼叫方式為$txt=big5togb($txt)。
    (註:原始碼中的include "data_big5.php";這個檔案在就是一個數組,在http://caocao.oso.com.cn/data_big5.zip,請編輯下載到oso上,做一個鏈接,因為這個文件我過幾天就要刪除了。)

/**************************************************** ******** ********************
                       由作者中:caocao
   🎜>                        http://caocao .oso.com.cn
在凱斯的幫助下
                              http://my-wjl.scu.edu.cn/~Keyes
***** *********** *************************************** ******************* ******/
function isbig5($code)
{
  if (strlen($code)>=2)
  {
 $代碼,"");
    if (ord($code[0])     {
      return (0);
    }
    其他
    {
      if (((ord($code[1]) >= 64)&(ord)($ ord($code[1]) >= 161)&&(ord($code[1])       {
        return (1);
      }
      其他
      {
      
      }
    }
  }
  else
  {
   
  }
}
函數big5offset($code)
{
  if (strlen($code) >= 2)
  {
  「」);
    if ((ord($code[1]) >= 64)&&(ord($code[1])     {
   代碼[ 0]) - 161) * 157 + (ord($code[1]) - 64));
    }
    if ((ord($code[1]) >= 161)    if ((ord($code[1]) >&(ord ($code[1])     {
      return ((ord ($code[0]) - 161) * 157 + 63 + (ord($code[1]) - 161) * 161) );
    }
  }
  返回(-1);
}
函數wordtostring($code)
{
  0,2))).chr(hexdec(substr($code,2,2) )))));
}
函數big5togb($code)
{
  include "data_big5.php ";
  $output="";
  $length=strlen($code);
  $code=strtok($code,"");
  ($idx   {
    $tmpStr=$code[$idx].$code[$idx+1];
    >      $offset=big5offset($tmpStr);
      if (($offset >= 0)||($offset         $idx++;
      }
       
      }
    }
    其他
    {
   
    }
    $idx++;
  }
  返回($輸出);
}
? >  
【論文版權歸作者與奧索網共同擁有,如需轉載,請版權作者與
以上就介紹了繁體中文繁體中文轉換為簡體中文的PHP函數,包括繁體中文方面的內容,希望對PHP教程有興趣的朋友得到幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn