Created
March 20, 2014 17:47
-
-
Save kfriend/9669711 to your computer and use it in GitHub Desktop.
PHP: Get list of all tags used in an XML document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set('memory_limit', '400M'); | |
$doc = new DOMDocument(); | |
$doc->loadXML(file_get_contents('/path/to/xml/file.xml')); | |
$xpath = new DOMXpath($doc); | |
$nodes = $xpath->query('//*'); | |
$names = array(); | |
foreach ($nodes as $node) | |
{ | |
$names[] = $node->nodeName; | |
} | |
echo join(PHP_EOL, array_unique($names)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello! How i can get all tags in HTML document, using PHP, without some external librares? I need to find all the tags on a page and count their number. Any ideas?