How to add CDATA tags when PHP generates XML
The example in this article describes how to add CDATA tags when PHP generates XML. Share to everyone for your reference. The implementation method is as follows:
In fact, it is very simple to add CDATA tags to PHP when generating XML, because it is a label that can store a variety of content in XML, and the following is an example to help you.
There is a code has the truth, paste the code, we do not regard $text as the prefix, in fact, it can be a label.
The specific code is as follows:
The code is as follows:
$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 is sliced into square pieces");
$root->appendchild ($cdata);
Create PI
$pi = $dom->createprocessinginstruction ("pizza", "bake ()");
$root->appendchild ($PI);
Save and display tree
echo $dom->savexml ();
?>
http://www.bkjia.com/PHPjc/896778.html www.bkjia.com true http://www.bkjia.com/PHPjc/896778.html techarticle How to add CDATA tags when PHP generates XML The example in this article describes how to add CDATA tags when PHP generates XML. Share to everyone for your reference. The concrete implementation method is as follows: actually PHP generates ...