PHP Authoring App Interface (ii)-php generating XML data

Source: Internet
Author: User

Add method XML () in the reponse.php file;
public static function XML () {header (' content-type:text/xml '); $xml = "<?xml version= ' 1.0 ' encoding = ' UTF-8 '? >\n"; $xml. = "<root>\n"; $xml. = "<code>200</code>\n"; $xml. = "<message> Data return success </message>\n"; $xml. = "<data>\n"; $xml. = "<id>1</id>\n"; $xml. = "<name>singwa</name>\n"; $xml. = "</ Data>\n "; $xml. =" </root> "; echo $xml;}

XML () method analysis: 1, there are two ways to generate XML, one is to use the system API, there is a direct string concatenation. The method is to use string concatenation.
2, if the header ("Content-type:text/xml") is not added, then the following output format:



The header ("Content-type:text/xml") is added, and the XML format is fully output:



Special Note: You must ensure that the header ("Content-type:text/xml") is the first sentence of execution, UTF-8 the case of the added header ("Content-type:text/xml") will be an error, Because php file saving uft8 format is to output additional whitespace characters, the output XML stream of PHP files modified to ANSI format. The following is an error in the case of test.php for UTF-8 encoding:



3. Add code in the test.php file:
<?php    require_once ('./response.php ');    Response::xml ();? >

in the browser, enter:http://localhost/test.phpThe following results can be obtained:

PHP Authoring App Interface (ii)-php generating XML data

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.