当前位置:首页 > PHP教程 > PHP基础知识

PHPmb_convert_encoding文字编码的转换函数介绍

文字编码的转换mb_convert_encoding()
mb_convert_encoding( $str, $encoding1,$encoding2 )

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

实例1
复制代码 代码如下:

<?php
$str='硕编程:http://www.jb51.net';
echo mb_convert_encoding($str, "utf-8"); //编码转换为utf-8
?>

复制代码 代码如下:

<?php
$str='硕编程:http://www.jb51.net';
echo mb_convert_encoding($str, "utf-8", "gbk"); //已知原编码为gbk,转换为utf-8
?>

复制代码 代码如下:

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

php下编码转换函数mb_convert_encoding与iconv的使用说明
【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐