Use the iconv function: iconv (& quot; UTF-8 & quot;, & quot; gb2312 & quot;, & quot; abc Sunshine 123 & quot;); it is said that this is better, errors during conversion can be ignored! Iconv (& quot; UTF-8 & quot;, & quot; gb2312ignore & quot;
Use the iconv function:
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.net/manual/zh/function.mb-convert-encoding.php
Make a gbk to UTF-8
-
- Header ("content-type: text/html; charset = utf-8 ");
- Echo mb_convert_encoding ("my friends", "UTF-8", "gbk ");
- ?>
Another gb2312 to big5
-
- Header ("content-type: text/html; charset = big5 ");
- Echo mb_convert_encoding ("You are my friend", "big5", "gb2312 ");
- ?>
However, to use the above functions, you must install the 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;