Skip to content

Instantly share code, notes, and snippets.

@kfriend
Created March 20, 2014 17:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kfriend/9669711 to your computer and use it in GitHub Desktop.
Save kfriend/9669711 to your computer and use it in GitHub Desktop.
PHP: Get list of all tags used in an XML document
<?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));
@Arhat161
Copy link

Arhat161 commented Sep 6, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment