If the html tags of Your webpage are not fully displayed, some table tags are incomplete, leading to page confusion, or some html pages other than your content are included, we can write a function to complete html tags and filter out useless html tags.
Php: webpage HTML Tag Completion Method
Php uses the following method to enable auto-completion of HTML tags:
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;
}
Resolution:
Array_reverse (): This function switches the elements in the original array sequentially, creates a new array, and returns the result. If the second parameter is set to true, the key name of the element remains unchanged; otherwise, the key name is lost.
Array_search (): array_search (value, array, strict). This function looks for a key value in the array like in_array. If this value is found, the key name of the matching element is returned. If not found, false is returned. If the third parameter strict is set to true, the key name of the corresponding element is returned only when the data type and value are consistent.