Created
February 29, 2016 22:23
-
-
Save webmechanicx/232e406cab66b31f9f1d to your computer and use it in GitHub Desktop.
RegEx match open tags except XHTML self-contained tags
This file contains hidden or 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 | |
$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