Phpiconvmb_convert_encoding encoding conversion function. Use the iconv function: iconv (UTF-8, gb2312, abc Sunshine 123); it is said that this is better, you can ignore the error during conversion! Iconv (UTF-8, gb2312ignore, abc Sunshine 123); use the iconv function for mb_convert_encoding:
Iconv ("UTF-8", "gb2312", "abc Sunshine 123 ");
It is said that this is better, you can ignore the conversion error!
Iconv ("UTF-8", "gb2312 // ignore", "abc Sunshine 123 ");
For the usage of mb_convert_encoding, refer to the official website:
Http://cn.php tutorial. net/manual/zh/function. mb-convert-encoding.php
Make a gbk to UTF-8
<? Php
Header ("content-type: text/html; charset = utf-8 ");
Echo mb_convert_encoding ("my friends", "UTF-8", "gbk ");
?>
Another gb2312 to big5
<? Php
Header ("content-type: text/html; charset = big5 ");
Echo mb_convert_encoding ("You are my friend", "big5", "gb2312 ");
?>
However, to use the above functions, you need to install but enable mbstring Extension Library first.
Another function iconv in php is also used to convert string encoding, similar to the function above.
The following are examples:
Iconv-convert string to requested character encoding
(Php 4> = 4.0.5, php 5)
Mb_convert_encoding-convert character encoding
(Php 4> = 4.0.6, php 5)
Usage:
String mb_convert_encoding (string str, string to_encoding [, mixed from_encoding])
Enable mbstring extension Library first, and remove the extension library before extension = php_mbstring.dll in php. ini.
Mb_convert_encoding can specify multiple input encodings, which are automatically identified based on the content, but the execution efficiency is much lower than that of iconv;
Iconv (UTF-8, gb2312, abc Sunshine 123); it is said that this is better, you can ignore the error during conversion! Iconv (UTF-8, gb2312 // ignore, abc Sunshine 123); use mb_convert_encoding...