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!
不要忘记开会