PHP | DOMCharacterData substringData() Function Last Updated : 20 Feb, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The DOMCharacterData::substringData() function is an inbuilt function in PHP which is used to extracts a range of data from the node. Syntax: string DOMCharacterData::substringData( int $offset, int $count ) Parameters: This function accept two parameters as mentioned above and described below: $offset: It specifies the starting position of substring to extract. $count: It specifies the number of characters to extract. Return Value: This function returns the specified substring. Exceptions: DOM_INDEX_SIZE_ERR is raised if $offset is negative or greater than the number of 16-bit units in data, or if $count is negative. Below given programs illustrate the DOMCharacterData::substringData() function in PHP: Program 1 (Use PHP echo function to view substring): php <?php // Create a new DOM Document $dom = new DOMDocument('1.0', 'iso-8859-1'); // Create a div element $element = $dom->appendChild(new DOMElement('div')); // Create a DOMCdataSection $text = $element->appendChild( new DOMCdataSection('GeeksForGeeks')); // Get the substring $text = $text->substringData(0, 13); echo $text; ?> Output: GeeksForGeeks Program 2 (Creating HTML heading to view substring): php <?php // Create a new DOM Document $dom = new DOMDocument('1.0', 'iso-8859-1'); // Create a div element $element = $dom->appendChild(new DOMElement('div')); // Create a DOMCdataSection $text = $element->appendChild( new DOMCdataSection('GeeksForGeeks')); // Get the substring $text = $text->substringData(0, 13); // Create a new element $elementnew = $dom->createElement('h1', $text); // We insert the new element $dom->appendChild($elementnew); echo $dom->saveXML(); ?> Output: Reference: https://www.php.net/manual/en/domcharacterdata.substringdata.php Comment More infoAdvertise with us Next Article PHP | xml_set_character_data_handler() Function G gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-DOM Similar Reads PHP | DOMCharacterData replaceData() Function The DOMCharacterData::replaceData() function is an inbuilt function in PHP which is used to replace a substring within the DOMCharacterData node. Syntax: void DOMCharacterData::replaceData( int $offset, int $count, string $data) Parameters: This function accept three parameters as mentioned above an 2 min read PHP | DOMCharacterData insertData() Function The DOMCharacterData::insertData() function is an inbuilt function in PHP which is used to insert a string at the specified 16-bit unit offset. Syntax: void DOMCharacterData::insertData( int $offset, string $data ) Parameters: This function accept two parameters as mentioned above and described belo 2 min read PHP | DOMCharacterData appendData() Function The DOMCharacterData::appendData() function is an inbuilt function in PHP which is used to append the string to the end of the character data of the node. Syntax: public DOMCharacterData::appendData( string $data ) Parameters: This function accepts a single parameter $data which holds the string tha 2 min read PHP | DOMCharacterData deleteData() Function The DOMCharacterData::deleteData() function is an inbuilt function in PHP which is used to remove a range of characters from the node. Syntax: void DOMCharacterData::deleteData( int $offset, int $count ) Parameters: This function accept two parameters as mentioned above and described below: $offset: 1 min read PHP | xml_set_character_data_handler() Function The xml_set_character_data_handler() function is an inbuilt function in PHP which is used to set the character data handler function for XML parser. Syntax: bool xml_set_character_data_handler( resource $xml_parser, callable $data_handler ) Parameters: This function accepts two parameters as mentio 3 min read PHP XMLWriter endCdata() Function The XMLWriter::endCdata() function is an inbuilt function in PHP which is used to end current CDATA. CDATA is block of text which is not parsed by the parser but are recognized as markup. Syntax: bool XMLWriter::endCdata( void ) Parameters: This function doesnât accept any parameter. Return Value: 2 min read Like