免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6510 | 回复: 5
打印 上一主题 下一主题

simplexml_load_file() 不支持GB2312 编码问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-09-29 01:54 |只看该作者 |倒序浏览
本帖最后由 yangzhengbo2002 于 2010-09-29 01:57 编辑

freebsd 环境
在用simplexml_load_file()载入xml文件的时候,提示以下错误:
Warning: simplexml_load_file()  [function.simplexml-load-file]: Config.xml:1: parser error : Unsupported encoding gb2312 in /usr/local/www/test3.php on line 2

Warning: simplexml_load_file() [function.simplexml-load-file]: <?xml version="1.0" encoding="gb2312"?> in /usr/local/www/test3.php on line 2

Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /usr/local/www/test3.php on line 2
bool(false)


test3.php内容:
<?php
$config = simplexml_load_file('Config.xml');
var_dump($config);
?>



Config.xml 文件内容:
<?xml version="1.0" encoding="gb2312"?>
<Config>
    <title>你好啊!</title>   
    <content>欢迎到来!</content>
</Config>

哪位能指点下,如何才能让simplexml_load_file()支持gb2312,是在哪个地方配置,谢谢!

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
2 [报告]
发表于 2010-09-29 10:48 |只看该作者

  1. <?php
  2. $config = simplexml_load_file('Config.xml');
  3. var_dump($config);
  4. readfile('Config.xml');
  5. echo phpversion();
  6. ?>
复制代码

  1. ---------- PHP5 代码调试 ----------
  2. object(SimpleXMLElement)#1 (2) {
  3.   ["title"]=>
  4.   string(10) "你好啊!"
  5.   ["content"]=>
  6.   string(13) "欢迎到来!"
  7. }
  8. <?xml version="1.0" encoding="gb2312"?>
  9. <Config>
  10.     <title>你好啊!</title>   
  11.     <content>欢迎到来!</content>
  12. </Config>
  13. 5.2.14
  14. 输出完成 (耗时 0 秒) - 正常终止
复制代码

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
3 [报告]
发表于 2010-09-29 10:52 |只看该作者

  1. %php -f t.php
  2. object(SimpleXMLElement)#1 (2) {
  3.   ["title"]=>
  4.   string(10) "浣犲ソ鍟"
  5.   ["content"]=>
  6.   string(13) "娆㈣繋鍒版潵!"
  7. }
  8. <?xml version="1.0" encoding="gb2312"?>
  9. <Config>
  10.     <title>你好啊!</title>   
  11.     <content>欢迎到来!</content>
  12. </Config>
  13. 5.2.10%uname -a
  14. FreeBSD www.com.cn 7.2-RELEASE FreeBSD 7.2-RELEASE #0
复制代码
iconv安装了吗?

论坛徽章:
0
4 [报告]
发表于 2010-09-29 11:04 |只看该作者
iconv
iconv support  enabled  
iconv implementation  libiconv  
iconv library version  1.11  

Directive Local Value Master Value
iconv.input_encoding ISO-8859-1 ISO-8859-1
iconv.internal_encoding ISO-8859-1 ISO-8859-1
iconv.output_encoding ISO-8859-1 ISO-8859-1

iconv  也安装了,
uname -a
FreeBSD www.test.com 7.2-RELEASE FreeBSD 7.2-RELEASE #0:
iconv  也安装了,

论坛徽章:
0
5 [报告]
发表于 2010-09-29 11:18 |只看该作者
<?php
$config = simplexml_load_file('Config.xml');
var_dump($config);
readfile('Config.xml');
echo phpversion();
?>


输出结果:
Warning: simplexml_load_file()  [function.simplexml-load-file]: Config.xml:1: parser error : Unsupported encoding gb2312 in /usr/local/www/test3.php on line 2

Warning: simplexml_load_file() [function.simplexml-load-file]: <?xml version="1.0" encoding="gb2312"?> in /usr/local/www/test3.php on line 2

Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /usr/local/www/test3.php on line 2
bool(false) 欢迎到来! 5.2.9


Config.xml内容:

<?xml version="1.0" encoding="gb2312"?>
<Config>
    <title>你好啊!</title>   
    <content>欢迎到来!</content>

论坛徽章:
0
6 [报告]
发表于 2010-09-29 14:17 |只看该作者
环境问题.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP