求iconv的替代函數,該如何解決

來源:互聯網
上載者:User
求iconv的替代函數
網上找了下,沒對照表,求一個,最好自己試過的,發我郵箱吧amani1234#21cn.com,謝謝

------解決方案--------------------


PHP code
/*******************************//GB轉UTF-8編碼*******************************/function gb2utf8($gbstr) { global $CODETABLE; if(trim($gbstr)=="") return $gbstr; if(empty($CODETABLE)){  $filename = dirname(__FILE__)."/gb2312-utf8.table";  $fp = fopen($filename,"r");  while ($l = fgets($fp,15))  { $CODETABLE[hexdec(substr($l, 0, 6))] = substr($l, 7, 6); }  fclose($fp); } $ret = ""; $utf8 = ""; while ($gbstr) {  if (ord(substr($gbstr, 0, 1)) > 127) {   $thisW = substr($gbstr, 0, 2);   $gbstr = substr($gbstr, 2, strlen($gbstr));   $utf8 = "";   @$utf8 = u2utf8(hexdec($CODETABLE[hexdec(bin2hex($thisW)) - 0x8080]));   if($utf8!=""){    for ($i = 0;$i < strlen($utf8);$i += 3)     $ret .= chr(substr($utf8, $i, 3));   }  }  else  {   $ret .= substr($gbstr, 0, 1);   $gbstr = substr($gbstr, 1, strlen($gbstr));  } } return $ret;}//Unicode轉utf8function u2utf8($c) { for ($i = 0;$i < count($c);$i++)  $str = ""; if ($c < 0x80) {  $str .= $c; } else if ($c < 0x800) {  $str .= (0xC0 | $c >> 6);  $str .= (0x80 | $c & 0x3F); } else if ($c < 0x10000) {  $str .= (0xE0 | $c >> 12);  $str .= (0x80 | $c >> 6 & 0x3F);  $str .= (0x80 | $c & 0x3F); } else if ($c < 0x200000) {  $str .= (0xF0 | $c >> 18);  $str .= (0x80 | $c >> 12 & 0x3F);  $str .= (0x80 | $c >> 6 & 0x3F);  $str .= (0x80 | $c & 0x3F); } return $str;}
------解決方案--------------------
樓主看下這個文章:http://neture.homeip.net/digiland/viewtopic.php?pid=39
下載地址osc_iconv.zip
裡面有對照表的

如果需要非要使用,建議在php中開啟iconv吧。
------解決方案--------------------
建議還是不要自己寫了
------解決方案--------------------
強烈建議使用內建的,自己寫對照表肯定不全
iconv 能處理的字元集有很多,自己寫的肯定不能全包括
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.