PHP | DOMNodeList item() Function Last Updated : 17 Mar, 2020 Comments Improve Suggest changes Like Article Like Report The DOMNodeList::item() function is an inbuilt function in PHP which is used to retrieve a node specified by index. Syntax: DOMNode DOMNodeList::item( int $index ) Parameters: This function accepts a single parameter $index which holds the index. Return Value: This function returns the DOMNode specified by the index. Below examples illustrate the DOMNodeList::item() function in PHP: Example 1: php <?php // Create a new DOMDocument instance $document = new DOMDocument(); // Create a div element $element = $document->appendChild(new DOMElement('div')); // Create a h1 element $text1 = new DOMElement('h1', 'GeeksforGeeks'); // Create another h1 elements $text2 = new DOMElement('h1', 'Another GeeksforGeeks'); // Append the nodes $element->appendChild($text1); $element->appendChild($text2); // Get all elements with tag name 'h1' $elements = $document->getElementsByTagName('h1'); // Get the text of first element echo $elements->item(0)->textContent; ?> Output: GeeksforGeeks Example 2: php <?php // Create a new DOMDocument instance $document = new DOMDocument(); // Create a div element $element = $document->appendChild(new DOMElement('div')); // Create a h1 element $text1 = new DOMElement('h1', 'GeeksforGeeks'); // Create another h1 elements $text2 = new DOMElement('h2', 'Another GeeksforGeeks'); // Append the nodes $element->appendChild($text1); $element->appendChild($text2); // Get all elements $elements = $document->getElementsByTagName('*'); // Get the name of tag of third element echo $elements->item(2)->nodeName; ?> Output: h2 Reference: https://www.php.net/manual/en/domnodelist.item.php Comment More infoAdvertise with us Next Article PHP | DOMNodeList item() Function G gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-DOM Similar Reads PHP | DOMNamedNodeMap item() function The DOMNamedNodeMap::item() function is an inbuilt function in PHP which is used to retrieve a node specified by index. This function is used to get a specific attribute from an element and further we can get the name or value of that attribute as per requirements. Syntax: DOMNamedNodeMap DOMNamedNo 2 min read PHP | DOMNode normalize() Function The DOMNode::normalize() function is an inbuilt function in PHP which is used to remove empty text nodes and merge adjacent text nodes in this node and all its children. Syntax: void DOMNode::normalize( void ) Parameters: This function doesnât accept any parameters. Return Value: This function does 2 min read PHP | DOMNode getLineNo() function The DOMNode::getLineNo() function is an inbuilt function in PHP which is used to get the line number for where the node is defined. Syntax: DOMNode DOMNode::getLineNo( void ) Parameters:This function doesnât accept any parameter. Return Value: This function returns the line number where the node was 2 min read PHP | DOMNode isSameNode() Function The DOMNode::isSameNode() function is an inbuilt function in PHP which indicates if two nodes are the same node or not. Syntax: bool DOMNode::isSameNode( DOMNode $node ) Parameters: This function accepts a single parameter $node which holds the node to be compared. Return Value: This function return 2 min read PHP | DOMNode insertBefore() Function The DOMNode::insertBefore() function is an inbuilt function in PHP which is used to insert a new node before a certain another node. Syntax: DOMNode DOMNode::insertBefore( DOMNode $newNode, DOMNode $refNode ) Parameters:This function accepts two parameters as mentioned above and described below: $ne 2 min read Like