Home > php教程 > php手册 > php生成xml时添加CDATA标签

php生成xml时添加CDATA标签

WBOY
Release: 2016-05-25 16:42:13
Original
1639 people have browsed it

php生成xml时添加CDATA标签方法非常的简单,因为是一个在xml中可以存储各种内容的标签了,下面整理了一个例子希望对各位有帮助.

贴上代码留住伤疤,不要把当成前后缀,其实它可以是标签,代码如下:

<?php 
	 
	$dom = new DOMDocument("1.0"); 
	// display document in browser as plain text 
	// for readability purposes 
	header("Content-Type: text/plain"); 
	// create root element 
	$root = $dom->createElement("toppings"); 
	$dom->appendChild($root); 
	// create child element 
	$item = $dom->createElement("item"); 
	$root->appendChild($item); 
	// create text node 
	$text = $dom->createTextNode("pepperoni"); 
	$item->appendChild($text); 
	// create attribute node 
	$price = $dom->createAttribute("price"); 
	$item->appendChild($price); 
	// create attribute value node 
	$priceValue = $dom->createTextNode("4"); 
	$price->appendChild($priceValue); 
	// create CDATA section 
	$cdata = $dom->createCDATASection(" Customer requests that pizza be sliced into 16 square pieces "); 
	$root->appendChild($cdata); 
	// create PI 
	$pi = $dom->createProcessingInstruction("pizza", "bake()"); 
	$root->appendChild($pi); 
	// save and display tree 
	echo $dom->saveXML(); 
	 
Copy after login

本文地址:

转载随意,但请附上文章地址:-)

Related labels:
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template