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: