Skip to content
Related Articles

Related Articles

Improve Article

PHP | DOMText __construct() Function

  • Last Updated : 13 Mar, 2020

The DOMText::__construct() function is an inbuilt function in PHP which is used to create a new DOMText object.


public DOMText::__construct( string $value )

Parameters: This function accepts a single parameter $value which holds the text.

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

Program 1:

// Create the text Node
$text = new DOMText('GeeksforGeeks');
// Get the Value
echo $text->nodeValue;



Program 2:

// Create a new DOMDocument instance
$document = new DOMDocument();
// Create a h1 element
$element = $document->appendChild(new DOMElement('h1'));
// Create the text Node
$text1 = new DOMText('GeeksforGeeks');
// Append the node
// Render the output
echo $document->saveXML();


<?xml version="1.0"?>


My Personal Notes arrow_drop_up
Recommended Articles
Page :