header('Content-Type:text/xml');中的:是英文下的:,不是中文下的:否则php会当做没有使用header('Content-Type:text/xml');仍然按照html解析下面的xml文档了
下面例子是正确的,
<?php
/****XML文档
****/
header('Content-Type:text/xml');
?>
<?xml version='1.0' encoding='utf-8'?>
<bookstore><book bid='b008'><title>天龙八部</title><intro>人生太苦了</intro></book></bookstore>
执行结果如下:
如果代码如下:(与上面不同的只是::)
<?php
/****
XML文档
****/
header('Content-Type:text/xml');
?>
<?xml version='1.0' encoding='utf-8'?>
<bookstore><book bid='b008'><title>天龙八部</title><intro>人生太苦了</intro></book></bookstore>
执行结果是:
本文介绍了在PHP中设置Content-Type为text/xml时需要注意的问题,特别是冒号字符的使用,确保服务器正确解析XML文档。
1822

被折叠的 条评论
为什么被折叠?



