Detailed explanation based on the use of php iconv functions

  • 2020-06-12 08:44:40
  • OfStack

To install module of PHP under unix, you need to recompile PHP. To install template under Windows, you just need to open the corresponding dll configuration in ES6en. ini.
extension_dir = "C:/ipaddr/php/extensions/"
(Note that it is recommended to write the full address and add/after it. In many cases, it is not possible to load dll of other modules due to the incorrect setting.)
And on again
extension=php_gd2.dll
However, if you want to install ES18en. dll, open php_ES21en. dll in the above method, and the iconv module still cannot be opened, you need the following configuration:
a. Go to iconv's official download site
http://ftp.gnu.org/pub/gnu/libiconv/
The iconv Windows version below files: libiconv - 1.9.1. bin. woe32. zip
Extract this file and 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 also calls GNU's iconv library, so install GNU's iconv library first.

b. Open php_iconv.dll in ES59en.ini

c. Restart Apache, then on phpinfo(); Check whether iconv is on or not.
Recently, I was working on a program, which needed to use iconv function to convert the captured utf-8 encoded page into gb2312. It was found that only using iconv function to transcode the captured data 1 data would be 1 less for no reason. Let me depressed for a while, go to the Internet 1 to look up information before I know that this is an bug iconv function. iconv made an error converting the character "-" to gb2312
The solution is simply to add "//IGNORE", the second argument of the iconv function, after the code to be converted.
The following are the quotes:
iconv("UTF-8","GB2312//IGNORE",$data)
ignore means to ignore conversion errors. Without the ignore argument, all strings following the character cannot be saved.

This function, iconv(), is built into php5. Thank you.

example


<?php
echo $str= ' hello , This is coffee !';
echo '<br />';
echo iconv('GB2312', 'UTF-8', $str);      // Encodes the string from GB2312 Go to the UTF-8
echo '<br />';
echo iconv_substr($str, 1, 1, 'UTF-8');   // Truncated by number of characters, not bytes          
print_r(iconv_get_encoding());            // Gets the current page encoding information 
echo iconv_strlen($str, 'UTF-8');         // Gets the string length of the specified encoding 
// It's also used in this way 
   $content = iconv("UTF-8","gbk//TRANSLIT",$content); 
?>


Related articles: