_php tutorial on using PHP iconv functions

Source: Internet
Author: User
Unix Install PHP module, need to recompile php,windows under the installation template, just the configuration in the php.ini to open the appropriate DLL, for example, need to join the GB library support, the following settings are required:
Extension_dir = "c:/ipaddr/php/extensions/"
(Note that it is recommended to write the full address, and then add/, many times because it is not set here, it is not possible to load other modules of the DLL)
Open it again.
Extension=php_gd2.dll
However, if the installation of Iconv.dll, according to the above method, open Php_iconv.dll, still cannot open the Iconv module, the following configuration is required:
A. Official download site on Iconv
http://ftp.gnu.org/pub/gnu/libiconv/
The following Windows version of 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, this step is necessary, Php_iconv.dll is also called GNU Iconv Library, so first install the GNU Iconv Library)

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

C. Restart Apache, and then in Phpinfo (); detect if Iconv is turned on.
Recently in a program, you need to use the ICONV function to fetch the UTF-8 encoded page into gb2312, found that only with the ICONV function to fetch the data of a transcoding data will be less for no reason. Let me depressed for a while, go online a check information to know this is a iconv function of a bug. Iconv error when converting character "-" to gb2312
The workaround is simply to add "//ignore" to the second parameter of the ICONV function after the code that needs to be converted.
The following is the referenced content:
Iconv ("UTF-8", "Gb2312//ignore", $data)
Ignore means ignoring errors at the time of conversion, and if there is no ignore argument, all strings after that character cannot be saved.

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

Liezi
Copy the Code code as follows:
echo $str = ' Hello, here is coffee! ';
Echo '
';

echo iconv (' GB2312 ', ' UTF-8 ', $str); To transfer the encoding of a string from GB2312 to UTF-8
Echo '
';

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

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

That's what it's used for.

$content = Iconv ("UTF-8", "Gbk//translit", $content);
?>

http://www.bkjia.com/PHPjc/327515.html www.bkjia.com true http://www.bkjia.com/PHPjc/327515.html techarticle Unix under the installation of PHP module, you need to recompile php,windows under the installation template, just the configuration in the php.ini to open the appropriate DLL, for example, need to join the GB library support, need the following ...

  • 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.