如何用PHP自动关闭打开的html标签?

kam*_*mal 2 html php

我在php和mysql上开发了很多站点.
我在获取像我使用的某些单词时遇到问题

SELECT *,left('<field>',200) from < table >
Run Code Online (Sandbox Code Playgroud)

由于没有关闭打开的标签,我在整个网站的布局上遇到了问题.
任何建议都会很棒.

我使用strip_tags()然后substr()裁剪文本.
但我需要一个永久的解决方案.

更新

<?php
$fragment = '<p>What a mighty fine <a href="blah">da';
$tidy = new tidy();
$tidy->parseString($fragment,array('show-body-only'=>true),'utf8');
$tidy->cleanRepair();
echo $tidy;
?>
Run Code Online (Sandbox Code Playgroud)

php_tidy extension通过php.ini在localhost中启用它,它的工作原理.

kam*_*mal 7

<?php
$fragment = '<p>What a mighty fine <a href="blah">da';
$tidy = new tidy();
$tidy->parseString($fragment,array('show-body-only'=>true),'utf8');
$tidy->cleanRepair();
echo $tidy;
?>
Run Code Online (Sandbox Code Playgroud)

php_tidy extension通过php.ini在localhost中启用它,它的工作原理.