php生成xml字符串
我现在有个检索后的结果集
USER_ID = 1
USER_NAME= 小张
POINT = 80
USER_ID = 2
USER_NAME=小李
POINT = 60
USER_ID = 3
USER_NAME= 小王
POINT = 70
想生成一个xml的字符串如下
"
请教各位大侠怎么实现啊
------解决方案--------------------
$xml =
<exportdata>
xml;
while($row = mysql_fetch_assoc($queryResult) )
{
$xml .=
<id>{$row['USER_ID']}</id><name>{$row['USER_NAME']}</name><point>{$row['POINT']}</point>
xml;
}
$xml .=
</exportdata>
xml;
<br><font color="#e78608">------解决方案--------------------</font><br>右键源代码。。。<br>想要标准的输出xml 在echo之前加上 header('Content-Type:text/xml');
<br><font color="#e78608">------解决方案--------------------</font><br>那是因为浏览器把这个XML字符串当html文档解析了,你可以通过查看源代码看到完整的结果。<br>在代码的最前面加一句 header('Content-type: text/xml; charset=UTF-8'); ,<br>并且把 <br>$xml = <?xml version='1.0' encoding='UTF-8'?><br>中的 <?xml 挪到最前面去,前面不能有任何输出。<br /><br>一切ok <div class="clear"></div>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号