http://blog.sina.com.cn/s/blog_4b3251540100eivb.html
使用举例:
1、把 GBK 编码字串转换成 UTF-8 编码字串 view plaincopy toclipboardprint?
<?php
header("content-Type: text/html;charset=Utf-8");
echomb_convert_encoding("你是我的好朋友","UTF-8","GBK");
?>
2、把 UTF-8 编码字串转换成 GB2312 编码字串 view plaincopy toclipboardprint?
// 注意将此文件存盘成
<?php
header("content-Type:text/html;charset=gb2312");
echomb_convert_encoding("你是我的好朋友","gb2312","utf-8");
?>
// 注意将此文件存盘成
<?php
header("content-Type: text/html;charset=gb2312");
echomb_convert_encoding("你是我的好朋友","gb312","utf-8");
?>
3、对整个页面进行转换
该方法适用所有编码环境。这样把前128个字符以外(显示字符)的字符集都用
在php文件的头部加上下面三行代码:
view plaincopy to clipboardprint?
mb_internal_encoding(”gb2312″);
mb_http_output(”HTML-ENTITIES”);
ob_start(’mb_output_handler’);
mb_internal_encoding(”gb2312″);
使用mb_convert_encoding 函数需启用PHP 的mbstring (multi-byte string)扩展。