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.
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
$text = new DOMText( 'GeeksforGeeks' );
echo $text ->nodeValue;
?>
|
Output:
GeeksforGeeks
Program 2:
<?php
$document = new DOMDocument();
$element = $document ->appendChild( new DOMElement( 'h1' ));
$text1 = new DOMText( 'GeeksforGeeks' );
$element ->appendChild( $text1 );
echo $document ->saveXML();
?>
|
Output:
<?xml version="1.0"?>
<h1>GeeksforGeeks</h1>
Reference: https://www.php.net/manual/en/domtext.construct.php
Share your thoughts in the comments
Please Login to comment...