Skip to content

Instantly share code, notes, and snippets.

@kfriend
Created March 9, 2016 04:15
Show Gist options
  • Save kfriend/c4a6cca30dd590968770 to your computer and use it in GitHub Desktop.
Save kfriend/c4a6cca30dd590968770 to your computer and use it in GitHub Desktop.
Quick and dirty way to get all HTML/XML tags in a string
<?php
function get_unique_tags($data) {
preg_match_all('/<([^>]+)>/i', $data, $matches);
$matches = $matches[1];
foreach ($matches as $i => $match) {
$matches[$i] = trim($match, '/');
}
$matches = array_unique($matches);
return $matches;
}
$data = '<foo>lorem ipsum</foo><p>lorem ipsum</p>';
var_dump(get_unique_tags($data));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment