PHP | DOMDocument createCDATASection() Function
Last Updated :
27 Aug, 2019
The DOMDocument::createCDATASection() function is an inbuilt function in PHP which is used to create a new instance of class DOMCDATASection.
Syntax:
DOMCDATASection DOMDocument::createCDATASection( string $data )
Parameters: This function accepts single parameter $data which holds the content of the cdata.
Return Value: This function returns the new DOMCDATASection on success or FALSE on failure.
Below programs illustrate the DOMDocument::createCDATASection() function in PHP:
Program 1:
<?php
$domDocument = new DOMDocument( '1.0' , 'iso-8859-1' );
$domElement = $domDocument ->createCDATASection( 'GeeksforGeeks' );
$domDocument ->appendChild( $domElement );
echo $domDocument ->saveXML();
?>
|
Output:
<?xml version="1.0" encoding="iso-8859-1"?>
<![CDATA[GeeksforGeeks]]>
Program 2:
<?php
$domDocument = new DOMDocument( '1.0' , 'iso-8859-1' );
$domComment = $domDocument ->createComment( 'Create CDATA file' );
$domElement = $domDocument ->createCDATASection( 'GeeksforGeeks' );
$domDocument ->appendChild( $domComment );
$domDocument ->appendChild( $domElement );
echo $domDocument ->saveXML();
?>
|
Output:
<?xml version="1.0" encoding="iso-8859-1"?>
<!--Create CDATA file-->
<![CDATA[GeeksforGeeks]]>
Reference: https://www.php.net/manual/en/domdocument.createcdatasection.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...