_php techniques based on PHP iconv function

Source: Internet
Author: User

UNIX Installation of PHP module, you need to recompile php,windows installation template, just php.ini in the configuration to open the corresponding DLL, for example, need to join the GB library support, you need to set the following:
Extension_dir = "c:/ipaddr/php/extensions/"
(Note that it is recommended to write a full address, and then add/, many times because it is not set here to cause the DLL of other modules to be loaded)
and then open
Extension=php_gd2.dll
However, if you are installing Iconv.dll, press the above method, after opening php_iconv.dll, still cannot open iconv module, need to configure as follows:
A. Official download site on the Iconv
http://ftp.gnu.org/pub/gnu/libiconv/
The following Windows version of the Iconv file: Libiconv-1.9.1.bin.woe32.zip
Unzip the file and copy the charset.dll,iconv.dll,iconv.exe below bin/to c:/windows/(or other system path)
(IPAddr reminds you that this step is necessary, Php_iconv.dll also calls the GNU Iconv Library, so install the GNU Iconv Library first)

B. Open the Php_iconv.dll inside the php.ini

C. Restart Apache, then Phpinfo (), and check to see if Iconv is turned on.
Recently in doing a program, need to use the ICONV function to crawl over the Utf-8 encoded page into gb2312, found that only use the ICONV function to crawl over the data a transcoding data will be less for a reason. Let me depressed for a while, go to the Internet to check the data to know that this is the iconv function of a bug. Iconv error when converting character "-" to gb2312
The solution is simple: After the code that needs to be converted, add "//ignore", which is the second parameter of the ICONV function.
The following are the referenced contents:
Iconv ("UTF-8", "Gb2312//ignore", $data)
Ignore means ignoring the conversion error, and if there is no ignore argument, all the strings after that character cannot be saved.

This function, Iconv (), is built into the PHP5. Thank you.

Liezi

Copy Code code as follows:

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

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

Echo Iconv_substr ($STR, 1, 1, ' UTF-8 '); Intercept by number of characters rather than bytes
Print_r (Iconv_get_encoding ()); Get current page encoding information

Echo Iconv_strlen ($str, ' UTF-8 '); Gets the string length of the set encoding

That's what it's for.

$content = Iconv ("UTF-8", "Gbk//translit", $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.