simplexml_load_file加载带参数的url的话就显示空白页面

hqaht 2011-01-18 05:44:47

<?php
$xml = simplexml_load_file('http://www.etdexpress.com/TrackingXML.aspx?trackingcodes=20600000075_20100000011');

foreach($xml as $item)
{
var_dump($item);
echo "\r\n<br>";
echo "\r\n<br>";
foreach ($item->TrackingInfo as $resulte){
$info = $resulte->attributes();
var_dump($info['ActionDate']);
echo "\r\n<br>";
echo "\r\n<br>";
}
//var_dump($arr['ActionDate']);
//getXMLnode($item,)
echo "\r\n<br>";
echo "\r\n<br>";
}
?>

以上代码在我本地可以正常运行
但是放到linux服务器上就只显示空白页面
我测试了如果把url换成http://www.abc.com/1.xml这种形式的话 就可以在服务器上运行
请达人告知,应该是服务器设置的问题,具体是哪里出了问题还请明示 (顺便做个广告哈,小弟的个人站艾莱依旗舰店-艾莱依羽绒服专卖店

补充:服务器php.ini的设置allow_url_fopen = On也打开了
...全文
283 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
hqaht 2011-01-28
  • 打赏
  • 举报
回复
SimpleXML
Simplexml support enabled
Revision $Revision: 299424 $
Schema support enabled

这个是支持的 但不知道还有哪块没有打开~
hqaht 2011-01-19
  • 打赏
  • 举报
回复
报错:
Warning: simplexml_load_file(http://www.etdexpress.com/TrackingXML.aspx?trackingcodes=20600000075_20100000011) [function.simplexml-load-file]: failed to open stream: HTTP request failed!
hqaht 2011-01-19
  • 打赏
  • 举报
回复
期待着高手给点拨,我可以继续加分
ihefe 2011-01-19
  • 打赏
  • 举报
回复
查看 phpinfo 对比看看是否缺少什么模块
hqaht 2011-01-19
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ihefe 的回复:]
测试成功 linux(ubuntu 10+) mac 10.6.6
[/Quote]
你在你的服务器上测试成功对我一点帮助都没有 我的本地也是一点问题也没有,关键是服务器上是哪里的问题 是php设置的问题还是其他方面呢
hqaht 2011-01-19
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 skyaspnet 的回复:]
引用楼主 hqaht 的回复:
PHP code

<?php
$xml = simplexml_load_file('http://www.etdexpress.com/TrackingXML.aspx?trackingcodes=20600000075_20100000011');

foreach($xml as $item)
{
var_dump($item);
echo……
[/Quote]

我的版本是PHP Version 5.2.6-1+lenny8

Since PHP 5.1.0 you don't need to do this because PHP will do it for you.

所以应该没问题啊~
skyaspnet 2011-01-19
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 hqaht 的回复:]
引用 4 楼 skyaspnet 的回复:
引用楼主 hqaht 的回复:
PHP code

<?php
$xml = simplexml_load_file('http://www.etdexpress.com/TrackingXML.aspx?trackingcodes=20600000075_20100000011');

foreach($xml as $item)
{
……
[/Quote]

代码在我这边测试没问题,应该是扩展的原因了,你检查一下phpinfo();

看一下是否有

SimpleXML
Simplexml support enabled
Revision $Revision: 299424 $
Schema support enabled


没有的话就不行,再检查一下其他的扩展是否正确打开了
skyaspnet 2011-01-18
  • 打赏
  • 举报
回复
刚好今天在做这个功能,可以考虑使用

file_get_content('http://www.etdexpress.com/TrackingXML.aspx?trackingcodes=20600000075_20100000011')


来完成,但是一定要注意你访问的这个文件是符合标准的XML文档,不然在解析时肯定会出错
skyaspnet 2011-01-18
  • 打赏
  • 举报
回复
[Quote=引用楼主 hqaht 的回复:]
PHP code

<?php
$xml = simplexml_load_file('http://www.etdexpress.com/TrackingXML.aspx?trackingcodes=20600000075_20100000011');

foreach($xml as $item)
{
var_dump($item);
echo "\r\n<br……
[/Quote]

注意一下PHP的版本,早期的PHP版本需要再进一些参数处理

simplexml_load_file
(PHP 5)

simplexml_load_file — Interprets an XML file into an object

说明
object simplexml_load_file ( string $filename [, string $class_name = "SimpleXMLElement" [, int $options = 0 [, string $ns [, bool $is_prefix = false ]]]] )
Convert the well-formed XML document in the given file to an object.

参数

filename
Path to the XML file

Note:

Libxml 2 unescapes the URI, so if you want to pass e.g. b&c as the URI parameter a, you have to call simplexml_load_file(rawurlencode('http://example.com/?a=' . urlencode('b&c'))). Since PHP 5.1.0 you don't need to do this because PHP will do it for you.

ihefe 2011-01-18
  • 打赏
  • 举报
回复
测试成功 linux(ubuntu 10+) mac 10.6.6
hqaht 2011-01-18
  • 打赏
  • 举报
回复
错误报告一直打开的没有提示
而且打印$xml返回的是false
明天VS今天 2011-01-18
  • 打赏
  • 举报
回复
把错误报告打开 看看有啥错误提示没

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧