您的位置:首页 > 编程语言 > PHP开发

Web_PHP_php的iconv()函数用于理中文乱码;

2015-01-03 10:40 411 查看
1、语法

// 把$message字串从utf-8编码转换成gbk编码

iconv('utf-8', 'gbk', $message);

2、示例

->xml文件

<?xml version="1.0" encoding="gbk"?>
<note xmlns:b="http://www.w3school.com.cn/example/">
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<b:body>Don't forget the meeting!</b:body>
<b:body>不要忘记开会!</b:body>
</note>

->PHP代码
<?php
// 加载XML文件
$xml = simplexml_load_file("test.xml");
// 设置xpath命名空间
$xml->registerXPathNamespace("msg", "http://www.w3school.com.cn/example/");
// 查找body元素
$result = $xml->xpath("msg:body");
// 循环body元素数组
foreach ($result as $message)
{
// //将字符串编码由utf8转变成gbk;
$message = iconv('utf-8', 'gbk', $message);
echo $message.'<br/>';
}
?>


->结果输出
Don't forget the meeting!

不要忘记开会
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: