php iconv function to use _php skills

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags address configuration content data echo example function gnu

Unix module installed under PHP need to recompile PHP, Windows installation template, just the configuration in php.ini dll can be opened, for example, the need to join the gb library support, you need the following settings:
extension_dir = "C: / ipaddr / php / extensions /"
(Note that it is recommended to write the full address, and followed by /, often because of the wrong settings here, it led to the dll can not load other modules)
Open again
extension = php_gd2.dll
But if it is to install iconv.dll, according to the above method, open php_iconv.dll, still can not open the iconv module, you need the following configuration:
a. The iconv official download site
http://ftp.gnu.org/pub/gnu/libiconv/
The following Windows version of the iconv file: libiconv-1.9.1.bin.woe32.zip
Unzip this file, copy bin / charset.dll, iconv.dll, iconv.exe to c: / windows / (or other system PATH)
(ipaddr reminds you that this step is necessary, php_iconv.dll is also called the GNU iconv library, so, first to install the GNU iconv library)

b. Open php.ini inside php_iconv.dll

c restart Apache, and then phpinfo (); detect iconv open.
Recently done a program, the need to use the iconv function to crawl the utf-8 encoding page into gb2312 and found only iconv function to grab the data over a transcoded data will be for no reason less. Let me depressed for a while, go online to check the information to know this is a bug in the iconv function. iconv in the conversion of characters "-" to gb2312 mistakes The solution is very simple, need to turn into the code plus "// IGNORE" iconv function is the second parameter, as follows:
The following is quoted content:
iconv ("UTF-8", "GB2312 // IGNORE", $ data)
Ignore means ignore the conversion error, without the ignore parameter, all the characters after the string can not be saved.

This iconv () function, built in php5, thanks.

Liezi

<? php
Echo $ str = 'Hello, here is selling coffee!';
echo '<br />';

echo iconv ('GB2312', 'UTF-8', $ str); // Move the encoding of the string from GB2312 to UTF-8
echo '<br />';

echo iconv_substr ($ str, 1, 1, 'UTF-8'); // By the number of characters instead of the number of bytes
print_r (iconv_get_encoding ()); // Get the current page encoding information

echo iconv_strlen ($ str, 'UTF-8'); // get the length of the set encoding string

// This is also used

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

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.