无法使用WAMPServer从PHP导出XML

无法使用WAMPServer从PHP导出XML,php,xml,wampserver,Php,Xml,Wampserver,我正在本地计算机上使用WAMPServer2.1。我试图创建一个简单的PHP脚本来输出XML文件。我无法让它在IE和Chrome上运行而不产生错误。在Firefox4上,它可以工作 以下是PHP: <?php main(); function main() { header("Content-type: application/xml"); OutputXML('xml/login_user_good.xml'); exit(0); } function Ou

我正在本地计算机上使用WAMPServer2.1。我试图创建一个简单的PHP脚本来输出XML文件。我无法让它在IE和Chrome上运行而不产生错误。在Firefox4上,它可以工作

以下是PHP:

<?php

main();

function main()
{
    header("Content-type: application/xml");
    OutputXML('xml/login_user_good.xml');
    exit(0);
}

function OutputXML($filename)
{
    echo file_get_contents($filename);
}

?>
在Firefox4上,我得到了格式正确的XML输出

在任何浏览器上,当我查看源代码时,我都可以看到正确的XML

我尝试过使用和不使用显式标题。如果删除对PHP header()函数的调用,将得到以下结果:

  • IE 8:与以前相同的错误
  • Firefox4:空白屏幕
  • Chrome 10:空白屏幕
同样,如果我在任何浏览器中查看源代码,我都可以看到XML。我尝试使用text/html而不是application/xml,但没有效果

我尝试过直接在PHP代码中生成XML,如下所示:

<?php

main();

function main()
{
    header("Content-type: application/xml");
    OutputXML();
    exit(0);
}

function OutputXML()
{
echo <<<END
<?xml version="1.0" encoding="utf-8" ?>
<login_user>
    <result_code value="1"/>
    <error value="Invalid username or password"/>
</login_user>
END;

}

?>

在PHP开始标记之前,您的脚本可能包含不需要的和不可见的字符(如BOM)

浏览器不用于显示任意XML。他们喜欢HTML(可以是XHTML)。不清楚为什么您希望浏览器显示这些内容。如果它是为一个和用户设计的,那么你应该用HTML来格式化它们,如果它是为一个API(服务)设计的,那么就用curl/wget/etc来检查它,我确信每次XMl看起来都是一样的

The XML page cannot be displayed  Cannot view XML input using style sheet.
Please correct the error and then click the Refresh button, or try again later. 
--------------------------------------------------------------------------------
Invalid at the top level of the document. Error processing resource
'http://localhost/kiamobile/login_user.php'. Line 1, P...

<?xml version="1.0" encoding="utf-8" ?> 
^
This page contains the following errors:

error on line 1 at column 6: XML declaration allowed only at the start of the document
<?php

main();

function main()
{
    header("Content-type: application/xml");
    OutputXML();
    exit(0);
}

function OutputXML()
{
echo <<<END
<?xml version="1.0" encoding="utf-8" ?>
<login_user>
    <result_code value="1"/>
    <error value="Invalid username or password"/>
</login_user>
END;

}

?>