PHP | DOMDocument getElementsByTagName() Function Last Updated : 27 Aug, 2019 Comments Improve Suggest changes Like Article Like Report The DOMDocument::getElementsByTagName() function is an inbuilt function in PHP which is used to return a new instance of class DOMNodeList which contains all the elements of local tag name. Syntax: DOMNodeList DOMDocument::getElementsByTagName( string $name ) Parameters: This function accepts single parameter $name which holds the local tag name to match. The value * is used to match all tags. Return Value: This function returns a new DOMNodeList object containing all the matched elements. Below program illustrates the DOMDocument::getElementsByTagName() function in PHP: Program: php <?php // Store the XML document to the variable $xml = <<< XML <?xml version="1.0" encoding="utf-8"?> <organization> <name>GeeksforGeeks</name> <address>Noida India</address> <contact> <email>[email protected]</email> <mobile>+91-987654321</mobile> </contact> </organization> XML; // Create new DOMDocument $dom = new DOMDocument; // Load the XML document $dom->loadXML($xml); // Use getElementsByTagName() function to search // all elements with given local tag name $org = $dom->getElementsByTagName('contact'); foreach ($org as $contact) { echo $contact->nodeValue, PHP_EOL; } ?> Output: [email protected] +91-987654321 Reference: https://www.php.net/manual/en/domdocument.getelementsbytagname.php Comment More infoAdvertise with us Next Article PHP | DOMDocument getElementsByTagName() Function J jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP | DOMDocument getElementsByTagnameNS() Function The DOMDocument::getElementsByTagNameNS() function is an inbuilt function in PHP which is used to search for all elements with given tag name in specified namespace. Syntax: DOMNodeList DOMDocument::getElementsByTagNameNS( string $namespaceURI, string $localName ) Parameters: This function accepts t 2 min read PHP | DOMElement getElementsByTagName() Function The DOMElement::getElementsByTagName() function is an inbuilt function in PHP which is used to get the elements by tagname. Syntax:Â DOMNodeList DOMElement::getElementsByTagName( string $name ) Parameters: This function accepts a single parameter $name which holds the tag name or use * for getting a 2 min read PHP | DOMElement getElementsByTagNameNS() Function The DOMElement::getElementsByTagNameNS() function is an inbuilt function in PHP which is used to get all the descendant elements with a given localName and namespaceURI. Syntax: DOMNodeList DOMElement::getElementsByTagNameNS( string $namespaceURI, string $localName ) Parameters: This function accept 2 min read PHP | DOMDocument getElementById() Function The DOMDocument::getElementById() function is an inbuilt function in PHP which is used to search for an element with a certain id. Syntax: DOMElement DOMDocument::getElementById( string $elementId ) Parameters:This function accepts a single parameter $elementId which holds the id to search for. Retu 2 min read PHP | DOMDocument load() Function The DOMDocument::load() function is an inbuilt function in PHP which is used to load an XML document from a file. Syntax: mixed DOMDocument::load( string $filename, int $options = 0 ) Parameters: This function accepts two parameters as mentioned above and described below: $filename: This parameter h 1 min read Like