Tuesday, October 7, 2025
HomeLanguagesPHP | DOMText __construct() Function

PHP | DOMText __construct() Function

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

Syntax:

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:




<?php
  
// Create the text Node
$text = new DOMText('neveropen');
  
// Get the Value
echo $text->nodeValue;
?>


Output:

neveropen

Program 2:




<?php
// 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('neveropen');
  
// Append the node
$element->appendChild($text1);
  
// Render the output
echo $document->saveXML();
?>


Output:

<?xml version="1.0"?>
<h1>neveropen</h1>

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

RELATED ARTICLES

Most Popular

Dominic
32338 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6708 POSTS0 COMMENTS
Nicole Veronica
11872 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11936 POSTS0 COMMENTS
Shaida Kate Naidoo
6827 POSTS0 COMMENTS
Ted Musemwa
7090 POSTS0 COMMENTS
Thapelo Manthata
6780 POSTS0 COMMENTS
Umr Jansen
6784 POSTS0 COMMENTS