If the HTML tags on your Web page are not fully displayed, some form tags are incomplete and the page is cluttered, or include local HTML pages that are outside of your content, we can write a functional approach to complement all HTML tags and filter out unwanted HTML tags.
A complete method of HTML tag in PHP implementation
PHP makes HTML tags automatically complement the closed function method as follows:
function Closetags ($html) {
Preg_match_all (' #< (?!) metaimgbrhrinput\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 argument is specified as true, the key name of the element remains unchanged or the key is lost.
Array_search (): Array_search (value,array,strict), which 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 argument strict is specified as true, the key name of the corresponding element is returned only if both the data type and the value are consistent.