免费注册 查看新帖 |

Chinaunix

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

php 5.2.9 版本simplexml_load_file() 不支持GB2312 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-09-29 11:30 |只看该作者 |倒序浏览
30可用积分

论坛徽章:
0
2 [报告]
发表于 2010-09-29 11:31 |只看该作者
附内容:
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,是在哪个地方配置,谢谢!

论坛徽章:
0
3 [报告]
发表于 2010-09-29 11:32 |只看该作者
附调试代码:
<?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
4 [报告]
发表于 2010-09-29 14:19 |只看该作者
环境问题,重新编译php。

  1. ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-debug --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-gettext --with-iconv --without-ldap
复制代码

论坛徽章:
0
5 [报告]
发表于 2010-09-29 14:22 |只看该作者
不是cgi模式,取消
  1. --enable-fastcgi --enable-force-cgi-redirect
复制代码

  1. ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-debug --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-gettext --with-iconv --without-ldap
复制代码

论坛徽章:
0
6 [报告]
发表于 2010-09-29 14:48 |只看该作者
本帖最后由 a.a 于 2010-09-29 14:54 编辑

我5.3.2 完全正常呀:object(SimpleXMLElement)[1]  public 'title' => string '你好啊!' (length=10)  public 'content' => string '欢迎到来!' (length=13)5.3.2


test3.php
  if(file_exists('Config.xml')){    $config = simplexml_load_file('Config.xml');
    var_dump($config);
    echo phpversion();
}else{
    exit('Config.xml not exist');
}

你可以尝试一下将gb2312换成其它的如utf-8看一下有什么效果!

论坛徽章:
0
7 [报告]
发表于 2010-09-29 15:04 |只看该作者
如果xml文件是utf-8的编码,加载是没有问题的,但程序说一定要支持gb2312才行,刚重新按照楼上的参数进行编译过了,还是不行,不支持gb2312

论坛徽章:
0
8 [报告]
发表于 2010-09-29 15:08 |只看该作者
难道是由于虚拟机的关系吗,折腾了好久了

论坛徽章:
0
9 [报告]
发表于 2010-09-29 16:51 |只看该作者
回复 1# yangzhengbo2002


    请确定文件本身的编码与<?xml version="1.0" encoding="Encoding">中的Encoding是否保持一致,很有可能是楼主测试的时候只是改了xml标记中的encoding而忘了文件本身

论坛徽章:
0
10 [报告]
发表于 2010-09-29 17:13 |只看该作者
file 一下 Config.xml
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP