PHP | DOMText splitText() Function
Last Updated :
13 Mar, 2020
The DOMText::splitText() function is an inbuilt function in PHP which is used to break a node into two nodes at the specified offset.
Syntax:
DOMText DOMText::splitText( int $offset )
Parameters: This function accepts a single parameter $offset which holds the offset to split.
Return Value: This function returns a new node of the same type, which contains all the content at and after the offset.
Below given programs illustrate the DOMText::splitText() function in PHP:
Program 1:
<?php
$text = new DOMText( 'GeeksforGeeks' );
$splitedtext = $text ->splitText(8);
echo $splitedtext ->nodeValue;
?>
|
Output:
Geeks
Program 2:
<?php
$document = new DOMDocument();
$element = $document ->appendChild( new DOMElement( 'div' ));
$text = $document ->createTextNode( 'GeeksforGeeks' );
$element ->appendChild( $text );
echo "Number of text nodes before splitting: " ;
echo count ( $element ->childNodes) . "<br>" ;
$text ->splitText(5);
echo "Number of text nodes after splitting: " ;
echo count ( $element ->childNodes);
?>
|
Output:
Number of text nodes before splitting: 1
Number of text nodes after splitting: 1
Reference: https://www.php.net/manual/en/domtext.splittext.php
Share your thoughts in the comments
Please Login to comment...