Php programming app interface (2)-PHP generating XML data-php Tutorial

Source: Internet
Author: User
Php programming app interface (2)-PHP generates XML data and adds the method xml () to the Reponse. php file ();
Public static function xml () {header ('content-type: text/XML'); $ xml ="
 \ N "; $ xml. ="
 
  
\ N "; $ xml. ="
  200\ N "; $ xml. ="
  
   
Data returned successfully
  \ N "; $ xml. ="
  \ N "; $ xml. ="
   
    
1
   \ N "; $ xml. ="
   
    
Singwa
   \ N "; $ xml. ="\ N "; $ xml. ="
 "; Echo $ xml ;}

Xml () method analysis: 1. there are two methods to generate XML. one is to use system APIs, and the other is to directly splice strings. This method is to concatenate strings.
2. if no header ("Content-Type: text/xml") is added, the following output format is used:



If the header ("Content-Type: text/xml") is added, the XML format is completely output:



Note: ensure that header ("Content-Type: text/xml") is the first sentence to be executed and header ("Content-Type: text/xml ") will report an error, because the uft8 format stored in the PHP file will output another blank character, and the PHP file of the output xml stream will be modified to the ANSI format. The following error is reported when test. php is coded as a UTF-8:



3. add the code to the test. php file:
 

Enter http: // localhost/test. php in the browser to get the following results:

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.