编码转换实验
来源:互联网 发布:网上兼职赚钱软件 编辑:程序博客网 时间:2024/05/21 07:46
一、utf-8 转换为 gb2312
〈?php
//header(“Content-Type:text/html; charset=utf-8“);
?〉
〈html xmlns=“http://www.w3.org/1999/xhtml“〉
〈head〉
〈meta http-equiv=“Content-Type“ content=“text/html; charset=utf-8“〉
〈/head〉
〈body〉
本页面编码是:utf-8 BOM〈br〉
〈?php
$str = ’陶喆’;
echo ’utf-8:’. $str;
echo ’〈br〉’;
$str = iconv(’utf-8’, ’gb2312//IGNORE’, $str); //convert to gb2312
//这是iconv函数的一个bug。iconv在转换字符到gb2312时会出错。
//解决方法很简单,就是在需要转成的编码后加 “//IGNORE“。
echo ’gb2312:’. $str;
echo ’〈br〉’;
$str = iconv(’gb2312’, ’utf-8’, $str); //再还原回来
//“喆“字没有了,是因为gb2312编码里没有这个字
//本身语法是正确的。变成 gbk 编码就可以了
echo ’utf-8:’. $str;
?〉
二、utf-8 转换为 gbk
〈?php
//header(“Content-Type:text/html; charset=utf-8“);
?〉
〈html xmlns=“http://www.w3.org/1999/xhtml“〉
〈head〉
〈meta http-equiv=“Content-Type“ content=“text/html; charset=utf-8“〉
〈/head〉
〈body〉
本页面编码是:utf-8 BOM〈br〉
〈?php
$str = ’陶喆’;
echo ’utf-8:’. $str;
echo ’〈br〉’;
$str = iconv(’utf-8’, ’gbk’, $str); //convert to gbk
echo ’gb2312:’. $str;
echo ’〈br〉’;
$str = iconv(’gbk’, ’utf-8’, $str); //再还原回来
echo ’utf-8:’. $str;
?〉
〈/body〉
[文章来源:“十万个为什么”电脑学习网]
[网络地址:http://why100000.com]
本文来自“十万个为什么”电脑学习网 http://www.why100000.com
- 编码转换实验
- 编码实验
- 实验一:算数编码实验
- 实验五:JPEG编码实验
- 编码转换
- 编码转换
- 编码转换
- 编码转换
- 编码转换
- 编码转换
- 编码转换
- 编码转换
- 编码转换
- 编码转换
- 编码转换
- 编码转换
- 编码转换
- 编码转换
- VoA English
- 传智播客——OA项目实战(一)
- 现讲述动态生成RSS文件的方法
- struts1异常处理
- Java 异常总结
- 编码转换实验
- javascript:String 对象
- 使用XMLHttprequest对象进行异步调用html页面的示例
- Struts1.2中的action配置
- 分布式之agent
- 我们的时代,Our times--沉默了许久想发言
- Gspay 和 95epay
- 软件的蓝海
- [经验总结]XSLT开发总结