如何在不破坏标签的情况下剪辑 HTML 片段?
假设我有一个包含 HTML 标记的 200 个字符的字符串.我想显示前 50 个字符的预览.无需拆分"标签.换句话说,片段不应该包含没有 </b>
的 <b>
.任何服务器端处理都应该在 PHP 中.
Say I have a 200 character string that contains HTML markup. I want to show a preview of just the first 50 chars. without 'splitting up' the tags. In other words, the fragment should not contain a <b>
without a </b>
. Any server side processing should be in PHP.
推荐答案
你应该检查输出 Tidy HTML. 只需在前 50 个非 HTML 字符之后将其剪切,然后通过 Tidy 运行以修复 HTML.
You should check out Tidy HTML. Just cut it after the first 50 non-HTML characters, then run it through Tidy to fix the HTML.
相关文章