Php Character Set conversion, php Character Set
PHP uses iconv to convert a string from gbk to the UTF8 character set.
1. iconv () Introduction
The iconv function can convert a known character set file to another known character set file. Example: Convert from GB2312 to UTF-8.
The iconv function is built in php5. The GB character set is enabled by default.
2. iconv () Error
Iconv will encounter an error when converting the characters "-" To gb2312. The solution is to add "// IGNORE" after the encoding to be converted, that is, after the second parameter of the iconv function:
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.
3. iconv () Example
<? Php echo $ str = 'Hello, I am selling coffee! '; Echo' <br/> '; echo iconv ('gb2312', 'utf-8', $ str ); // encode the string from GB2312 to the UTF-8 echo '<br/>'; echo iconv_substr ($ str, 1, 1, 'utf-8 '); // capture by the number of characters rather than the byte print_r (iconv_get_encoding (); // obtain the current page encoding information echo iconv_strlen ($ str, 'utf-8 '); // get the length of the specified encoded string?>
The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!