This article illustrates the usage of the character encoding conversion function in PHP, and shares it for everyone's reference. The implementation methods are as follows:
Generally speaking, in the Web page program, especially involves the reading of the database process, often the most annoying is the problem of character encoding, php4.0.6 above version provides mb_convert_encoding can facilitate the conversion of the code.
Specifically as follows:
Copy Code code as follows:
<?php
/* Convert internal character encoding to SJIS * *
$str = mb_convert_encoding ($str, "Sjis");
* Convert EUC-JP to UTF-7 * *
$str = mb_convert_encoding ($str, "UTF-7", "EUC-JP");
/* Auto detect encoding from JIS, Eucjp-win, Sjis-win, then convert str to UCS-2LE * *
$str = mb_convert_encoding ($str, "Ucs-2le", "JIS, Eucjp-win, Sjis-win");
/* "Auto" is expanded to "ascii,jis,utf-8,euc-jp,sjis" * *
$str = mb_convert_encoding ($str, "EUC-JP", "Auto");
?>
For example, to convert gb2312 strings into Utf-8, you can use the following methods:
Copy Code code as follows:
$str =mb_convert_encoding ($str, "UTF-8", "GB2312")
I hope this article will help you with your PHP program design.