Home  >  Article  >  Backend Development  >  PHP搞个echo XML都折磨疯哥了,该如何解决

PHP搞个echo XML都折磨疯哥了,该如何解决

WBOY
WBOYOriginal
2016-06-13 13:37:43940browse

PHP搞个echo XML都折磨疯哥了
$conn=mysql_connect("localhost","root","root");
if(!$conn){
echo "OK";
}
$query='SELECT * FROM rcuset order by no desc';
$result=mysql_db_query("test",$query);
echo "";
while($row = mysql_fetch_object($result)) {
  echo "no>";
  echo "".$row->ch."";
  echo "".$row->f."";
  echo "
";
}
echo "
";
mysql_free_result($result);
mysql_close();
?>
刚开始可以输出字符串。但是查看源文件是XML格式的
加了行header("Content-type:text/xml");
就提示
-----------------------
无法显示 XML 页。 
使用 XSL 样式表无法查看 XML 输入。请更正错误然后单击 刷新按钮,或以后重试。 


--------------------------------------------

XML 文档只能有一个顶层元素。处理资源 'http://localhost/getXML.php' 时出错。第 2 行,位置: 2 

Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\ge...
------------------------
后来去掉了那个header("Content-type:text/xml");
结果反而又没字符串了

纠结的哥蛋疼哦

------解决方案--------------------
因为你输出的是xml, 查看源文件就能看到了。
------解决方案--------------------
是你加上 header("Content-type:text/xml"); 这后出现的 

因为 在header前不能有什么的输出。
出这个错误是因为 header('Content-Type:text/html;');发送头之前不能有任何输出,空格也不行,你需要将header(...)之前的空格去掉,或者其他输出的东西去掉,或者把header 直接放到 程序最上面,保证没有什么输出。echo print_r var_dump 之类的输出形式
------解决方案--------------------
检查下代码。进行单步的调试和打印,来排查是哪里出现的问题。 给你看个 关于你那个错误的网上的一些解决方法。http://hi.baidu.com/xiaefun/blog/item/87fd5f82e96a3eaa0df4d2cb.html
------解决方案--------------------
我也碰到过这问题。问题一般出现在以下几点
1、去除BOM
2、不能出现除了XML外的其它字符
3、4、?>结束之后也不能有换行甚至一个空格
------解决方案--------------------
菜单栏-格式- 以UTF-8 无BOM格式编码
------解决方案--------------------
恩。。跟你一样
------解决方案--------------------

探讨

记事本的格式里没这一项啊?

------解决方案--------------------
你上面的代码是没问题的。你肯定是编码搞错了。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn