Skip to content

Instantly share code, notes, and snippets.

@AgelxNash
Created July 15, 2013 13:01
Show Gist options
  • Save AgelxNash/5999754 to your computer and use it in GitHub Desktop.
Save AgelxNash/5999754 to your computer and use it in GitHub Desktop.
CloseHtmlTag
<?php
function close_tag_html($text) {
preg_match_all("/<[^>]*>/", $text, $bal);
$liste = array();
foreach($bal[0] as $balise) {
if ($balise{1} != "/") { // opening tag
preg_match("/<([a-z]+)/i", $balise, $type);
// add the tag
$liste[] = $type[1];
} else { // closing tag
preg_match("/<\/([a-z]+)/i", $balise, $type);
// strip tag
for ($i=count($liste); $i>=0; $i--) if ($liste[$i] == $type[1]) $liste[$i] = "";
}
}
for ($i=count($liste); $i>=0; $i--) if ($liste[$i] != "") $tags .= '</'.$liste[$i].'>';
return($tags);
}
//echo html_entity_decode( close_tag_html('<div><span>Hello') );
//<div><span>Hello</span></div>
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment