PHP在文档错误结束时创建xml额外内容

时间:2013-02-22 12:33:09

标签: php xml

<?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 -->

1 个答案:

答案 0 :(得分:0)

它适用于您的WAMPP服务器,因为它不会输出您的主机添加的分析代码:

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

请联系您的主机,了解如何从输出中删除它(或者更好,切换主机,因为这有点令人发指)。