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!
不要忘记开会
// 把$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!
不要忘记开会
相关文章推荐
- 解决Java调用php web webService 中文参数乱码
- PHP UTF-8字符串截断函数实现中文字符的无乱码截断
- PHP json_encode() 函数详解及中文乱码问题
- php 字符串操作函数substr()截取中文子串乱码问题
- PHP的两个常用函数截取中文字符串无乱码与获取客户端IP地址
- PHP将汉字转化成拼音的函数(用于取首字母索引或按字母排序中文)
- Web_PHP_PHPsubstr截取中文字符出现乱码解决;
- PHP json_encode() 函数详解及中文乱码问题
- php关于使用iconv(...)函数对字符进行中文转换时,遇到的一个问题
- PHP自定义函数实现防止中文出现乱码
- php截取中文字符串无乱码的函数(主函数:ord()、substr())
- PHP 中文字符串截取无乱码的方法以及php汉字截取函数_preg_split()
- php使用NuSoap调用java/C# webservice的中文乱码问题
- php 读取xml的方法 (iconv解决中文乱码问题)
- PHP将汉字转化成拼音的函数(用于取首字母索引或按字母排序中文)
- PHP中的字符串截取函数,取子符串,以保证中文不出现乱码
- php-mail()函数发送UTF-8邮件-中文标题乱码
- PHP中文字符串截取无乱码方法,php汉字截取函数_preg_split()
- PHP的两个常用函数截取中文字符串无乱码与获取客户端IP地址
- PHP截取中文无乱码函数——cutstr