PHP | DOMNamedNodeMap item() function Last Updated : 19 Feb, 2020 Comments Improve Suggest changes Like Article Like Report 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 DOMNamedNodeMap::item( int $index ) Parameters:This function accepts a single parameter $index which holds the index. Return Value: This function returns a node at the index'th position in the map. Below given programs illustrate the DOMNamedNodeMap::item() function in PHP: Program 1: In this example, we will get the name of attributes after fetching them using index() php <?php // Create a new DOMDocument $dom = new DOMDocument(); // Load the XML $dom->loadXML("<?xml version=\"1.0\"?> <root> <html> <h1 id=\"first\" class=\"first\" attrib=\"attrib_value\"> Geeksforgeeks </h1> </html> </root>"); // Get the elements $node = $dom->getElementsByTagName('h1')[0]; // Get the 2nd attribute's value $attribute1 = $node->attributes->item(0)->nodeName; $attribute2 = $node->attributes->item(1)->nodeName; $attribute3 = $node->attributes->item(2)->nodeName; echo "$attribute1, $attribute2 and $attribute3"; ?> Output: id, class and attrib Program 2: In this example we will get the value of attributes after fetching them using index() php <?php // Create a new DOMDocument $dom = new DOMDocument(); // Load the XML $dom->loadXML("<?xml version=\"1.0\"?> <root> <html> <h1 id=\"first\" class=\"geeksforgeeks\" attrib=\"attrib_value\"> Geeksforgeeks </h1> </html> </root>"); // Get the elements $node = $dom->getElementsByTagName('h1')[0]; // Get the 2nd attribute's value $attribute1 = $node->attributes->item(0)->nodeValue; $attribute2 = $node->attributes->item(1)->nodeValue; $attribute3 = $node->attributes->item(2)->nodeValue; echo "$attribute1, $attribute2 and $attribute3"; ?> Output: first, geeksforgeeks and attrib_value Reference: https://www.php.net/manual/en/domnamednodemap.item.php Comment More infoAdvertise with us Next Article PHP | DOMNamedNodeMap item() function G gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP | DOMNamedNodeMap getNamedItem() Function The DOMNamedNodeMap::getNamedItem() function is an inbuilt function in PHP which is used to retrieve a node specified by name. This is used to get the attribute items and further get information about the attribute. Syntax: DOMNode DOMNamedNodeMap::getNamedItem( string $name ) Parameters: This funct 2 min read PHP | DOMNamedNodeMap getNamedItemNS() function The DOMNamedNodeMap::getNamedItemNS() function is an inbuilt function in PHP which is used to retrieve a node with a specific local name and namespace URI. This function can be used to get the value of a attribute from a specific namespace. Syntax: DOMNode DOMNamedNodeMap::getNamedItemNS ( string $n 2 min read PHP | DOMNamedNodeMap count() Function The DOMNamedNodeMap::count() function is an inbuilt function in PHP which is used to get the number of nodes in the map. It can be used to count attributes of a element. Syntax: int DOMNamedNodeMap::count( void ) Parameters: This function doesnât accepts any parameter. Return Value: This function re 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 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 Like