PHP - 完成尚未关闭的HTML标记?

时间:2011-08-15 17:10:44

标签: php html string formatting

假设我输入的内容如下:

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

我希望代码能够获取此字符串并将其转换为:

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

1 个答案:

答案 0 :(得分:5)

可能首先要看的是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;