PHP | DOMCdataSection __construct() Function

The DOMCdataSection::__construct() function is an inbuilt function in PHP which is used to construct a new DOMCdataSection object. DOMC stands for DOM Character and this section can further be manipulated using the methods of DOMCharacterData class. This CDATA node works like the DOMTEXT class.

Syntax:

public DOMCdataSection::__construct( string $value )

Parameters: This function accepts a single parameter $value which holds the value of the CDATA node.

Below given programs illustrate the DOMCdataSection::__construct() function in PHP:

Program 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new DOM Document
$dom = new DOMDocument('1.0', 'iso-8859-1');
  
// Create a div element
$element = $dom->appendChild(new DOMElement('div'));
  
// Create a DOMCdataSection 
$text = $element->appendChild(
    new DOMCdataSection('Hey this is my DOMC'));
  
echo $dom->saveXML();
?>

chevron_right


Output: Use Chrome Developer tools to view the HTML or press Ctrl+U

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new DOM Document
$dom = new DOMDocument('1.0', 'iso-8859-1');
  
// Create a div element
$element = $dom->appendChild(new DOMElement('div'));
  
// Create a DOMCdataSection 
$text = $element->appendChild(
    new DOMCdataSection('GeeksforGeeks'));
  
// Split the first 5 words
$text->splitText(5);
  
echo $dom->saveXML();
?>

chevron_right


Output:

Reference: https://www.php.net/manual/en/domcdatasection.construct.php




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.