Php-based xml string generation solution

Source: Internet
Author: User
Php generates an xml string. I now have a Retrieved result set USER_ID1USER_NAME. small Zhang POINT80USER_ID2USER_NAME Xiao Li POINT60USER_ID3USER_NAME Xiao Wang POINT70 wants to generate an xml string as follows & quot; & lt ;? Xmlversion1.0encodingU php generates xml strings
I now have a Retrieved result set.
USER_ID = 1
USER_NAME = Xiaozhang
POINT = 80

USER_ID = 2
USER_NAME = Xiao Li
POINT = 60

USER_ID = 3
USER_NAME = John
POINT = 70

The xml string to be generated is as follows:
"



1 80


2 Xiao Li 60


3 John 70


";
Ask you how to implement it.











------ Solution --------------------
PHP code
$ Xml = <
   
    Xml; while ($ row = mysql_fetch_assoc ($ queryResult) {$ xml. = <
          
     
      
{$ Row ['User _ id']}
           
     
      
{$ Row ['User _ name']}
           
     
      
{$ Row ['point']}
        Xml;} $ xml. = <
       
     
    
   Xml;
   
------ Solution --------------------
Right-click the source code...
Add the header ('content-Type: text/XML') before echo to the standard output xml ');
------ Solution --------------------
That's because the browser parses the XML string as an html document. you can view the complete result by checking the source code.
Add a header ('content-type: text/xml; charset = UTF-8 ') at the beginning of the code ');,
And
$ Xml = <
In
Everything OK

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.