PHP | DOMCharacterData insertData() Function Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report 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 below: $offset: It specifies the starting point to insert data. $data: It specifies the data to insert. Return Value: This function does not return any value. Below given programs illustrate the DOMCharacterData::insertData() function in PHP: Program 1: 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('GeeksGeeks')); // Insert 'For' between Geeks and Geeks $text->insertData(5, 'For'); echo $dom->saveXML(); ?> Output: <?xml version="1.0" encoding="iso-8859-1"?> <div><![CDATA[GeeksForGeeks]]></div> Use Chrome Developer tools to view the HTML or press Ctrl+U Program 2: 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('My DOM Characters')); // Insert in the beginning $text->insertData(0, 'Beginning'); echo $dom->saveXML(); ?> Output: <?xml version="1.0" encoding="iso-8859-1"?> <div><![CDATA[BeginningMy DOM Characters]]></div> Program 3: 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('My DOM Characters')); // Insert in the end $text->insertData(17, 'End'); echo $dom->saveXML(); ?> Output: <?xml version="1.0" encoding="iso-8859-1"?> <div><![CDATA[My DOM CharactersEnd]]></div> Reference: https://www.php.net/manual/en/domcharacterdata.insertdata.php Comment More infoAdvertise with us Next Article PHP | DOMCharacterData insertData() 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 substringData() Function 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: $off 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 Like