If the HTML tag of your Web page is incomplete, some of the table tabs are incomplete and the page is cluttered, or if you include a partial HTML page outside your content, we can write a function method to complement the HTML tag and filter out the useless HTML tags.
PHP implements HTML tag completion method for Web pages
PHP makes the HTML tag auto-complete closed function method as follows:
function Closetags ($html) {
Preg_match_all (' #< (?! meta|img|br|hr|input\b) \b ([a-z]+) (?:. *)? (? #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], $closedtags)) {
$html. = ' ;
} else {
Unset ($closedtags [Array_search ($openedtags [$i], $closedtags)]);
}
}
return $html;
}
Array_reverse (): This function flips the order of elements in the original array, creates a new array, and returns. If the second parameter is specified as true, the key name of the element remains unchanged or the key names are lost.
Array_search (): Array_search (value,array,strict), this function looks for a key value in the array like In_array (). If the value is found, the key name of the matching element is returned. Returns False if it is not found. If the third parameter, strict, is specified as true, the key name of the corresponding element is returned only if the data type and value are consistent.
http://www.bkjia.com/PHPjc/735882.html www.bkjia.com true http://www.bkjia.com/PHPjc/735882.html techarticle if the HTML tag of your Web page is incomplete, some of the table tabs are incomplete and the page is cluttered, or if you include a partial HTML page outside your content, we can write a letter ...