PHP头条
热点:

php 中文编码的转换之mb_convert_encoding()函数


在php中编码一直是开发人员的头痛的事情,但是如果甜美一些有用的函数就不一样了,下面我们介绍一下关于一个中文编码的处理函数。

mb_convert_encoding( $str, $encoding1,$encoding2 )

$str,要转换编码的字符串
$encoding1,目标编码,如utf-8,gbk,大小写均可
$encoding2,原编码,如utf-8,gbk,大小写均可

实例1

 代码如下 复制代码

<?php  
$str='电影618:http://www.111cn.net';
echo mb_convert_encoding($str, "UTF-8"); //编码转换为utf-8
?> 

实例2

 代码如下 复制代码

<?php  
$str='电影618:http://www.111cn.net';
echo mb_convert_encoding($str, "UTF-8", "GBK"); //已知原编码为GBK,转换为utf-8
?> 

实例3

 代码如下 复制代码

<?php  
$str='电影618:http://www.111cn.net';
echo mb_convert_encoding($str, "UTF-8", "auto"); //未知原编码,通过auto自动检测后,转换编码为utf-8
?>

php.net网站实例

 

 代码如下 复制代码

<?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");
?>

www.phpzy.comtrue/php/27400.htmlTechArticlephp 中文编码的转换之mb_convert_encoding()函数 在php中编码一直是开发人员的头痛的事情,但是如果甜美一些有用的函数就不一样了,下面我们介绍一下关于一个中文编码的处理函数。 mb_...

相关文章

PHP之友评论

今天推荐