Skip to content

Instantly share code, notes, and snippets.

@webmechanicx
Created February 29, 2016 22:23
Show Gist options
  • Save webmechanicx/232e406cab66b31f9f1d to your computer and use it in GitHub Desktop.
Save webmechanicx/232e406cab66b31f9f1d to your computer and use it in GitHub Desktop.
RegEx match open tags except XHTML self-contained tags
<?php
$selfClosing = explode(',', 'area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed');
$html = '
<p><a href="#">foo</a></p>
<hr/>
<br/>
<div>name</div>';
$dom = new DOMDocument();
$dom->loadHTML($html);
$els = $dom->getElementsByTagName('*');
foreach ( $els as $el ) {
$nodeName = strtolower($el->nodeName);
if ( !in_array( $nodeName, $selfClosing ) ) {
var_dump( $nodeName );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment