Examples of Character Transcoding Function Usage in php
- 2021-07-21 08:06:36
- OfStack
This article example narrates the php character code conversion function usage, shares to everybody for everybody reference. The specific implementation method is as follows:
1 Generally speaking, in web programs, especially when it comes to the reading process of databases, the most annoying thing is the problem of character encoding. php versions above 4.0. 6 provide mb_convert_encoding for convenient conversion and encoding.
The details are 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 the string of gb2312 to utf-8, you can use the following method:
$str=mb_convert_encoding($str,"UTF-8","GB2312")
I hope this article is helpful to everyone's PHP programming.