2012-04-03 81 views
0

我写了简单的代码来从xml文件获取内容到php。从外部xml文件加载xml内容到php

$xml = simplexml_load_file("http://localhost/xml_load/test_xml.xml"); 
print_r($xml); 

第一次它已成功运行,但现在它给了我警告,并没有正确执行。

Warning: simplexml_load_file(http://localhost/xml_load/test_xml.xml) [function.simplexml-load-file]: failed to open stream: HTTP request failed! <?xml version="1.0" encoding="ISO-8859-1"?> in C:\xampp\htdocs\XML_load\load_file.php on line 2 

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://localhost/xml_load/test_xml.xml" in C:\xampp\htdocs\XML_load\load_file.php on line 2 
+0

检查文件是否存在于给定位置。它可能已经被你的代码第一次修改了,它正确地加载了,现在给你提供了一些问题。 – 2012-04-03 12:28:50

+0

检查文件是否存在 – 2012-04-03 12:28:56

回答

0

在各自的位置没有找到文件。现在,检查您的文件是否存在。但是,请尝试使您的本地路径不基于BASEURL。进一步添加该路径

$xml = simplexml_load_file("xml/files/myxml.xml"); // PATH TO YOUR FILE. 
echo "<pre>"; print_r($xml); "</pre>"; 
+0

我不想传递物理路径。我的要求是从其他网址获取xml数据。 – 2012-04-04 04:54:20

+0

那么,它如何识别你的生产环境的'localhost'路径?但是,它显示您的文件缺少该文件。请按照这个'[链接](http://stackoverflow.com/a/9998960/1310324)' – 2012-04-04 10:15:33