PHP | DOMNamedNodeMap getNamedItem() Function Last Updated : 26 Feb, 2020 Comments Improve Suggest changes Like Article Like Report 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 function accepts a single parameter $name which holds the nodeName of the node to retrieve. Return Value: This function returns DOMNode with the specified name on success. Below examples illustrate the DOMNamedNodeMap::getNamedItem() function in PHP: Example 1: In this example we will get the attribute value of a element. 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\" style=\"color: blue\"> Geeksforgeeks </h1> </html> </root>"); // Get the elements $node = $dom->getElementsByTagName('h1')[0]; // Get the attribute value $attribute = $node->attributes-> getNamedItem('style')->nodeValue; echo $attribute; ?> Output: color: blue Example 2: In this example we will check if the function fetches the latest attribute values or not by altering the value of attribute. 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\"> Geeksforgeeks </h1> <h2> Second heading </h2> </html> </root>"); // Get the elements $node = $dom->getElementsByTagName('h1')[0]; echo "Before: <br>"; // Get the attribute value $attribute = $node->attributes-> getNamedItem('class')->nodeValue; echo $attribute; // Change the value of attribute $node->setAttribute('class', 'changed'); echo "<br>After: <br>"; // Get the attribute value $attribute = $node->attributes-> getNamedItem('class')->nodeValue; echo $attribute; ?> Output: Before: first After: changed Reference: https://www.php.net/manual/en/domnamednodemap.getnameditem.php Comment More infoAdvertise with us Next Article PHP | DOMNamedNodeMap getNamedItem() Function G gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-DOM Similar Reads 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 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 | 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 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 Like