Home >php教程 >php手册 >PHP mb_convert_encoding文字编码的转换函数介绍_php入门_脚本之

PHP mb_convert_encoding文字编码的转换函数介绍_php入门_脚本之

WBOY
WBOYOriginal
2016-06-06 20:39:221121browse

PHP mb_convert_encoding文字编码的转换函数介绍,可以将字符转换为gbk或utf8格式。

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

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

实例1
代码如下:
$str='脚本之家:http://www.jb51.net';
echo mb_convert_encoding($str, "UTF-8"); //编码转换为utf-8
?>

代码如下:
$str='脚本之家:http://www.jb51.net';
echo mb_convert_encoding($str, "UTF-8", "GBK"); //已知原编码为GBK,转换为utf-8
?>

代码如下:
$str='脚本之家:http://www.jb51.net';
echo mb_convert_encoding($str, "UTF-8", "auto"); //未知原编码,通过auto自动检测后,转换编码为utf-8
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn