【问题标题】:PHP create xml Extra content at the end of the document errorPHP create xml Extra content at the end of the document error
【发布时间】:2013-02-22 20:53:50
【问题描述】:
<?php 
// Display the error message according to each data code.
$xml = '<?xml version="1.0" encoding="utf-8"?><results>'; 
if($_GET['code'] == "500"){
    $xml .= '<error id="500" message="Error 500"></error>';     
}else if($_GET['code'] == "501"){
    $xml .= '<error id="501" message="Error 501"></error>'; 
}
$xml .= '</results>';
header ("Content-Type:text/xml"); 
echo ($xml);  
?>

我收到了这个错误

This page contains the following errors:

error on line 3 at column 1: Extra content at the end of the document
Below is a rendering of the page up to the first error.

明文形式

<?xml version="1.0" encoding="UTF-8"?><results><error id="501" message="Invalid Course Code"></error>   </results>  
   <!-- Hosting24 Analytics Code -->
   <script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
   <!-- End Of Analytics Code -->

【问题讨论】:

  • 您是否尝试在结果开始标记前换行?
  • 结果前换行是什么意思?
  • ?&gt; PHP 结束标记后没有多余的空格吗?
  • 能否显示浏览器错误报告的其余部分?
  • 或者更好的是完整的 XML 结果。

标签: php xml


【解决方案1】:

它可以在您的 WAMPP 服务器上运行,因为它不会输出您的主机似乎添加的分析代码:

   <!-- Hosting24 Analytics Code -->
   <script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
   <!-- End Of Analytics Code -->

联系您的主机商,了解如何从您的输出中删除它(或者更好的是,切换主机,因为这有点离谱)。

【讨论】: