How can I solve the problem of finding an iconv replacement function?

Source: Internet
Author: User
Tags comparison table
I have found the iconv substitution function online. I don't have a comparison table. I 'd like to find one. I 'd better try it myself. please send me an email address, amani1234 # 21cn.com. thank you, PHPcode/****************************** // GB to UTF-8 encoding * * ***** evaluate the iconv substitution function
I found it online and didn't check the table. I 'd better try it myself. please send me your email address amani1234 # 21cn.com. thank you.

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


PHP code
** * ***************************/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 to 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 ;}
------ Solution --------------------
Look at this post: http://neture.homeip.net/digiland/viewtopic.php? Pid = 39
Osc_iconv.zip
There is a comparison table

If you need to use iconv, we recommend that you enable iconv in php.
------ Solution --------------------
We recommend that you do not write it yourself.
------ Solution --------------------
We strongly recommend that you use a built-in table. you must not write the table yourself.
Iconv can process many character sets and cannot include all the characters written by itself.

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.