Starx Starx - 1 year ago 149
PHP Question

How to close unclosed HTML Tags?

Whenever we are fetching some user inputed content with some editing from the database or similar sources, we might retrieve the portion which only contains the opening tag but no closing.

This can hamper the website's current layout.

Is there a clientside or serverside way of fixing this?

Answer Source

Found a great answer for this one:

Use PHP 5 and use the loadHTML() method of the DOMDocument object. This auto parses badly formed HTML and a subsequent call to saveXML() will output the valid HTML. The DOM functions can be found here:

The usage of this:

$doc = new DOMDocument();
$yourText = $doc->saveHTML();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download