Home >Backend Development >PHP Tutorial >How to generate xml data in php
This article mainly introduces the method of generating XML data in PHP. It has certain reference value. Now I share it with you. Friends in need can refer to it.
1. There are generally 2 ways to generate XML data in PHP. There are two ways, one is to assemble strings, and the other is to use PHP’s built-in system classes
2. Use PHP’s built-in classes to generate xml data
3. Assemble strings to generate xml data
public function static 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>数据返回成功</message>\n"; $xml .= "<data>\n"; $xml .= "<id>1</id>\n"; $xml .= "<name>yangzl</name>\n"; $xml .= "</data>\n"; $xml .= "</root>\n"; echo $xml; } Respine::xml();
The above is the entire content of this article. I hope it will be helpful to everyone's learning. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
About the method of encapsulating data in xml
Explanation of PHP caching technology
The above is the detailed content of How to generate xml data in php. For more information, please follow other related articles on the PHP Chinese website!