The example in this article describes how PHP adds a CDATA tag when it generates XML. Share to everyone for your reference. The implementation methods are as follows:
 
In fact, PHP to generate XML when adding CDATA tag method is very simple, because it is a in the XML can store a variety of content in the tag, the following an example of a sample to help you.
 
There's a code that has the truth, put the codes on, everybody don't put <! [cdata[$text]]> as a prefix, in fact it can be a label.
The specific code is as follows:
 code is as follows: <?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 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 (); 
?>