PHP | DOMNamedNodeMap count() Function Last Updated : 26 Feb, 2020 Comments Improve Suggest changes Like Article Like Report 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 returns and integer value containing the number of nodes in the map. Below examples illustrate the DOMNamedNodeMap::count() function in PHP: Example 1: In this example we will count the attributes 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 count $attributeCount = $node->attributes->count(); echo 'No of attributes => ' . $attributeCount; ?> Output: No of attributes => 3 Example 2: In this example we will check if count function fetches the latest no of attributes or not by altering the number of attributes. 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 the addition of attributes: <br>"; // Get the attribute count $attributeCount = $node->attributes->count(); echo 'No of attributes => ' . $attributeCount; // Set the id attribute $node->setAttribute('new', 'value'); echo "<br>After the addition of attributes: <br>"; // Get the attribute count $attributeCount = $node->attributes->count(); echo 'No of attributes => ' . $attributeCount; ?> Output: Before the addition of attributes: No of attributes => 2 After the addition of attributes: No of attributes => 3 Reference: https://www.php.net/manual/en/domnamednodemap.count.php Comment More infoAdvertise with us Next Article PHP | DOMNamedNodeMap count() 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 C14N() Function The DOMNode::C14N() function is an inbuilt function in PHP which is used to convert a node into string. Syntax: string DOMNode::C14N( bool $exclusive, bool $with_comments, array $xpath, array $ns_prefixes ) Parameters: This function accepts four parameters as mentioned above and described below: $ex 2 min read 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 | DOMNode C14NFile() Function The DOMNode::C14NFile() function is an inbuilt function in PHP which is used to canonicalize nodes to a file. Syntax: int DOMNode::C14NFile( string $uri, bool $exclusive, bool $with_comments, array $xpath, array $ns_prefixes ) Parameters: This function accepts five parameters as mentioned above and 2 min read Like