Tuesday, December 23, 2025
HomeLanguagesPHP | DOMCdataSection __construct() Function

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:




<?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();
?>


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

Program 2:




<?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('neveropen'));
  
// Split the first 5 words
$text->splitText(5);
  
echo $dom->saveXML();
?>


Output:

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32456 POSTS0 COMMENTS
Milvus
111 POSTS0 COMMENTS
Nango Kala
6825 POSTS0 COMMENTS
Nicole Veronica
11959 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12038 POSTS0 COMMENTS
Shaida Kate Naidoo
6958 POSTS0 COMMENTS
Ted Musemwa
7203 POSTS0 COMMENTS
Thapelo Manthata
6912 POSTS0 COMMENTS
Umr Jansen
6890 POSTS0 COMMENTS