To find an alternative function of iconv, how to solve

Source: Internet
Author: User
Tags comparison table utf 8
An alternative function for finding iconv
Online to find the next, no comparison table, ask for a, the best of their own tried, send me mailbox amani1234#21cn.com, thank you

------Solution--------------------


PHP Code
/*******************************//GB to UTF-8 encoded *******************************/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, +)) {$CODETABLE [Hexdec (substr ($l, 0, 6)] = substr ($l, 7, 6);} Fclose ($FP); } $ret = ""; $utf 8 = "";   while ($GBSTR) {if (Ord (substr ($gbstr, 0, 1)) > 127) {$thisW = substr ($gbstr, 0, 2);   $gbstr = substr ($gbstr, 2, strlen ($GBSTR));   $utf 8 = "";   @ $utf 8 = U2utf8 (Hexdec ($CODETABLE [Hexdec (Bin2Hex ($thisW))-0x8080]));   if ($utf 8!= "") {for ($i = 0; $i < strlen ($utf 8); $i + 3) $ret. = Chr (substr ($utf 8, $i, 3));   }} else {$ret. = substr ($gbstr, 0, 1);  $gbstr = substr ($gbstr, 1, strlen ($GBSTR)); }} return $ret;} Unicode goto 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 >> & 0x3F);  $str. = (0x80 | $c >> 6 & 0x3F); $str. = (0x80 | $c & 0x3F); } return $str;}
------Solution--------------------
Landlord look at this post: http://neture.homeip.net/digiland/viewtopic.php?pid=39
Download the address Osc_iconv.zip
There's a chart in there.

If you need to use it, it is recommended to open Iconv in PHP.
------Solution--------------------
I suggest you don't write it yourself.
------Solution--------------------
It is strongly recommended to use the built-in, write your own table definitely not all
Iconv can handle a lot of character sets, their own writing must not include all
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.