Home > php教程 > php手册 > php iconv mb_convert_encoding编码转换函数

php iconv mb_convert_encoding编码转换函数

WBOY
Release: 2016-06-13 09:54:39
Original
1166 people have browsed it

用iconv函数:

iconv( "utf-8", "gb2312" , "abc阳光123");

据说这样好些,可以忽略转换时的错误!

iconv( "utf-8", "gb2312//ignore" , "abc阳光123");

mb_convert_encoding的用法见官方:
http://cn.php教程.net/manual/zh/function.mb-convert-encoding.php

做一个gbk to utf-8

header("content-type: text/html; charset=utf-8");
echo mb_convert_encoding("我的友仔", "utf-8", "gbk");
?>

再来个gb2312 to big5

header("content-type: text/html; charset=big5");
echo mb_convert_encoding("你是我的朋友", "big5", "gb2312");
?>


不过要使用上面的函数需要安装但是需要先enable mbstring 扩展库。

php中的另外一个函数iconv也是用来转换字符串编码的,与上函数功能相似。

下面还有一些详细的例子:
iconv — convert string to requested character encoding
(php 4 >= 4.0.5, php 5)
mb_convert_encoding — convert character encoding
(php 4 >= 4.0.6, php 5)

用法:
string mb_convert_encoding ( string str, string to_encoding [, mixed from_encoding] )
需要先enable mbstring 扩展库,在 php.ini里将; extension=php_mbstring.dll 前面的 ; 去掉
mb_convert_encoding 可以指定多种输入编码,它会根据内容自动识别,但是执行效率比iconv差太多;

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template