Detailed explanation of three methods of outputting XML to page content in PHP
Release: 2016-07-25 08:59:15
Original
896 people have browsed it
-
- header("Content-type: text/xml");
- echo "";
- echo "";
- echo "";
- echo "";
- echo "小小菜鸟";
- echo "";
- echo "";
- echo "24";
- echo "";
- echo "";
- echo "男";
- echo "";
- echo "";
- echo "";
- echo "";
- echo "艳艳";
- echo "";
- echo "";
- echo "23";
- echo "";
- echo "";
- echo "女";
- echo "";
- echo "";
- echo "";
- ?>
复制代码
方法2,
-
- header("Content-type: text/xml");
- echo "";
- echo "小小菜鸟24男艳艳23女";
- ?>
复制代码
方法3,
-
-
/* - 用PHP的DOM控件来创建XML输出
- 设置输出内容的类型为xml
- edit bbs.it-home.org
- */
- header('Content-Type: text/xml;');
- //创建新的xml文件
- $dom = new DOMDocument('1.0', 'utf-8');
//建立元素
- $response = $dom->createElement('response');
- $dom->appendChild($response);
//建立元素并将其作为的子元素
- $books = $dom->createElement('books');
- $response->appendChild($books);
//为book创建标题
- $title = $dom->createElement('title');
- $titleText = $dom->createTextNode('PHP与AJAX');
- $title->appendChild($titleText);
//为book创建isbn元素
- $isbn = $dom->createElement('isbn');
- $isbnText = $dom->createTextNode('1-21258986');
- $isbn->appendChild($isbnText);
//创建book元素
- $book = $dom->createElement('book');
- $book->appendChild($title);
- $book->appendChild($isbn);
//将作为子元素
- $books->appendChild($book);
//在一字符串变量中建立XML结构
- $xmlString = $dom->saveXML();
//输出XML字符串
- echo $xmlString;
- ?>
-
复制代码
|
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31