How to add CDATA tags when PHP generates XML _php tutorial

Source: Internet
Author: User
Tags cdata

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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.