note 68181 deleted from function.preg-match-all by felipe
| From: | felipe@php.net | Date: | Sun, 23 Mar 2008 22:57:54 +0000 |
| Subject: | note 68181 deleted from function.preg-match-all by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-137388@lists.php.net to get a copy of this message | ||
Note Submitter: mail at SPAMBUSTER at milianw dot de
----
I refurnished connum at DONOTSPAMME dot googlemail dot com autoCloseTags function:
<?php
/**
* close all open xhtml tags at the end of the string
*
* @author Milian Wolff <http://milianw.de>
* @param string $html
* @return string
*/
function closetags($html){
#put all opened tags into an array
preg_match_all("#<([a-z]+)( .*)?(?!/)>#iU",$html,$result);
$openedtags=$result[1];
#put all closed tags into an array
preg_match_all("#</([a-z]+)>#iU",$html,$result);
$closedtags=$result[1];
$len_opened = count($openedtags);
# all tags are closed
if(count($closedtags) == $len_opened){
return $html;
}
$openedtags = array_reverse($openedtags);
# close tags
for($i=0;$i<$len_opened;$i++) {
if (!in_array($openedtags[$i],$closedtags)){
$html .= '</'.$openedtags[$i].'>';
} else {
unset($closedtags[array_search($openedtags[$i],$closedtags)]);
}
}
return $html;
}
?>