Fermez le HTML-Tags

Auteur Nalivaeff Mai 5, 2009

Un autre aiguillon pour À ce moment, nous fermons les balises HTML non fermées. Je ne sais pas où elle pourrait m'être utile un jour ...


function closetags($html) {
$single_tags = array('meta','img','br','link','area','input','hr','col','param','base');
preg_match_all('~< ([a-z0-9]+)(?: .*)?(? ~iU', $html, $result);
$openedtags = $result[1];
preg_match_all('~~iU', $html, $result);
$closedtags = $result[1];
$len_opened = count($openedtags);
if (count($closedtags) == $len_opened) {
return $html;
}
$openedtags = array_reverse($openedtags);
for ($i=0; $i < $len_opened; $i++) {
if (!in_array($openedtags[$i], $single_tags)) {
if (FALSE !== ($key = array_search($openedtags[$i], $closedtags))) {
unset($closedtags[$key]);
}
else {
$html .= ' ';
}
}
}
return $html;
}

function closetags($html) {
$single_tags = array('meta','img','br','link','area','input','hr','col','param','base');
preg_match_all('~< ([a-z0-9]+)(?: .*)?(? ~iU', $html, $result);
$openedtags = $result[1];
preg_match_all('~~iU', $html, $result);
$closedtags = $result[1];
$len_opened = count($openedtags);
if (count($closedtags) == $len_opened) {
return $html;
}
$openedtags = array_reverse($openedtags);
for ($i=0; $i < $len_opened; $i++) {
if (!in_array($openedtags[$i], $single_tags)) {
if (FALSE !== ($key = array_search($openedtags[$i], $closedtags))) {
unset($closedtags[$key]);
}
else {
$html .= ' ';
}
}
}
return $html;
}

function closetags($html) {
$single_tags = array('meta','img','br','link','area','input','hr','col','param','base');
preg_match_all('~< ([a-z0-9]+)(?: .*)?(? ~iU', $html, $result);
$openedtags = $result[1];
preg_match_all('~~iU', $html, $result);
$closedtags = $result[1];
$len_opened = count($openedtags);
if (count($closedtags) == $len_opened) {
return $html;
}
$openedtags = array_reverse($openedtags);
for ($i=0; $i < $len_opened; $i++) {
if (!in_array($openedtags[$i], $single_tags)) {
if (FALSE !== ($key = array_search($openedtags[$i], $closedtags))) {
unset($closedtags[$key]);
}
else {
$html .= ' ';
}
}
}
return $html;
}

Regarda ici

Les entrées relatives

Catégorie: Tags Skriptulki:

Commentaires

Pas encore de commentaires.


Laissez un commentaire

(requis)

(requis)