Php Close Unclosed Html Tags

[Solved] Php Close Unclosed Html Tags | Php - Code Explorer | yomemimo.com
Question : php close unclosed HTML Tags

Answered by : borma425

function closetags($html) { preg_match_all('#<(?!meta|img|br|hr|input\b)\b([a-z]+)(?: .*)?(?<![/|/ ])>#iU', $html, $result); $openedtags = $result[1]; preg_match_all('#</([a-z]+)>#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 .= '</'.$openedtags[$i].'>'; } else { unset($closedtags[array_search($openedtags[$i], $closedtags)]); } } return $html;
} 

Source : https://stackoverflow.com/questions/3810230/close-open-html-tags-in-a-string/3810341 | Last Update : Thu, 27 May 21

Answers related to php close unclosed html tags

Code Explorer Popular Question For Php