RétroX
RétroX

Reputation: 2116

PHP - Finish HTML tags that haven't been closed?

Let's say that I get an input of something like:

<strong>bunch <em>of</em> <span>random text

I want code to be able to take this string and turn it into:

<strong>bunch <em>of</em> <span>random text</span></strong>

Upvotes: 1

Views: 146

Answers (1)

Michael Berkowski
Michael Berkowski

Reputation: 270775

Probably the first place to look is the Tidy extension

$html = "<strong>bunch <em>of</em> <span>random text";
$tidy = tidy_parse_string($html, array('clean' => true, 'show-body-only' => true));
$tidy->cleanRepair();
echo $tidy;

Upvotes: 5

Related Questions