修复未封闭的HTML标签 [英] Fixing unclosed HTML tags

查看:171
本文介绍了修复未封闭的HTML标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一些博客布局上工作,我需要创建一个每个帖子的摘要(比如说最后的15个),以便在主页上显示。现在我使用的内容已经在纺织品库的html标签中被格式化了。现在,如果我使用substr来获取第一个500字符的帖子,我面临的主要问题是如何关闭未封闭的标签。

I am working on some blog layout and I need to create an abstract of each post (say 15 of the lastest) to show on the homepage. Now the content I use is already formatted in html tags by the textile library. Now if I use substr to get 1st 500 chars of the post, the main problem that I face is how to close the unclosed tags.

eg

<div>.......................</div>
<div>...........
     <p>............</p>
     <p>...........| 500 chars
     </p>
<div>  

我得到的是两个未关闭的标签< p>和÷麻烦,但是div只是整个页面布局混乱。所以任何建议如何跟踪打开标签并手动关闭它们?

What I get is two unclosed tags <p> and <div> , p wont create much trouble , but div just messes with the whole page layout. So any suggestion how to track the opening tags and close them manually or something?

推荐答案

有很多可以使用的方法:

There are lots of methods that can be used:


  1. 使用正确的HTML解析器,如 DOMDocument

  2. 使用 PHP Tidy 修复未封闭的标签

  3. 有些会建议 HTML Purifier

  1. Use a proper HTML parser, like DOMDocument
  2. Use PHP Tidy to repair the un-closed tag
  3. Some would suggest HTML Purifier

这篇关于修复未封闭的HTML标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆