Home > Backend Development > PHP Tutorial > php生成xml字符串解决办法

php生成xml字符串解决办法

WBOY
Release: 2016-06-13 13:27:38
Original
911 people have browsed it

php生成xml字符串
我现在有个检索后的结果集
USER_ID = 1
USER_NAME= 小张
POINT = 80

USER_ID = 2
USER_NAME=小李
POINT = 60

USER_ID = 3
USER_NAME= 小王
POINT = 70

想生成一个xml的字符串如下
"



180


2小李60


3小王70


";
请教各位大侠怎么实现啊











------解决方案--------------------

PHP code
$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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template