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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

GeeksforGeeks

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

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

Reference: https://www.php.net/manual/en/domtext.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.