<?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也打开了
而且打印$xml返回的是false
注意一下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.
我的版本是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. 所以应该没问题啊~
Warning: simplexml_load_file(http://www.etdexpress.com/TrackingXML.aspx?trackingcodes=20600000075_20100000011) [function.simplexml-load-file]: failed to open stream: HTTP request failed!
代码在我这边测试没问题,应该是扩展的原因了,你检查一下phpinfo();看一下是否有SimpleXML
Simplexml support enabled
Revision $Revision: 299424 $
Schema support enabled
没有的话就不行,再检查一下其他的扩展是否正确打开了
Simplexml support enabled
Revision $Revision: 299424 $
Schema support enabled 这个是支持的 但不知道还有哪块没有打开~