我有一个php文件,我将标题设置为header ("content-type: text/xml");
。
当我尝试用simplexml_load_file()
读取文件时,它返回`false。
但是,如果我将扩展名设置为xml,则文件将正确读取。
我使用的是php 5.1.6。随着版本> 5.3一切正常。这是5.1.6版中的错误吗?可能是什么问题?
由于
答案 0 :(得分:2)
尝试将其作为文件获取,然后加载为字符串:
$str = file_get_contents($file);
$xml = simplexml_load_string($str);
答案 1 :(得分:0)
simple_xml_load_file('yourfile.php')
将执行基于文件的打开/读取,您将直接将原始PHP代码加载到simplexml中。 simple_xml_load_file('http://example.com/yourfile.php')
将执行完整的HTTP请求并导致执行yourfile.php,此时它应输出xml标头并输出xml文本。