Usage of php iconv Functions

Source: Internet
Author: User

To install the PHP module in unix, you need to re-compile PHP. to install the template in Windows, you only need. you can open the corresponding dll for the configuration in ini. For example, to add the support for the gb library, you need the following settings:
Extension_dir = "C:/ipaddr/php/extensions /"
(Note: it is recommended to write the full address and add/to it later. In many cases, the dll of other modules cannot be loaded because the setting is incorrect)
Open again
Extension = php_gd2.dll
However, if you install iconv. dll, follow the above method to enable the iconv module after enabling php_iconv.dll. The following configuration is required:
A. Download The iconv official website
Http://ftp.gnu.org/pub/gnu/libiconv/
The following Windows version of The iconv file: libiconv-1.9.1.bin.woe32.zip
Decompress the file and copy charset.dll, iconv.dll, and iconv.exe under bin/to c:/windows/(or another system PATH)
(Ipaddr reminds you that this step is required. php_iconv.dll also calls the GNU iconv library. Therefore, install the GNU iconv Library first)

B. Enable php_iconv.dll in php. ini.

C. Restart Apache and check whether iconv is enabled in phpinfo.
Recently, I am working on a program. I need to use the iconv function to convert the captured UTF-8 encoded page to gb2312, it is found that only the iconv function can be used to convert the captured data into less data for no reason. I was depressed for a while. I checked the information on the Internet to find out that this is a bug in the iconv function. Iconv will encounter an error when converting the character "-" To gb2312
The solution is simple. Add "// IGNORE" after the code to be converted, that is, the second parameter of the iconv function, as follows:
Reference content is as follows:
Iconv ("UTF-8", "GB2312 // IGNORE", $ data)
Ignore indicates that the conversion error is ignored. Without the ignore parameter, all strings after this character cannot be saved.

This iconv () function is built-in in php5. Thank you.

Column

Copy codeThe Code is as follows: <? Php
Echo $ str = 'Hi, it's coffee sale! ';
Echo '<br/> ';

Echo iconv ('gb2312', 'utf-8', $ str); // encode the string from GB2312 to UTF-8
Echo '<br/> ';

Echo iconv_substr ($ str, 1, 1, 'utf-8'); // truncate by number of characters rather than bytes
Print_r (iconv_get_encoding (); // obtain the encoding information of the current page.

Echo iconv_strlen ($ str, 'utf-8'); // you can specify the length of the encoded string.

// This is also applicable.

$ Content = iconv ("UTF-8", "gbk // Transcoder", $ content );
?>

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.