PHP:获取前 200 个字符时 HTML 标记中断
在我的 PHP Web 应用程序中,我有一个数据输入表单,用户将使用富文本编辑器(我使用的 FCKEditor)输入数据,并将标记从编辑器保存到数据库表中。在另一个页面中,我必须显示前 200 个内容的字符(使用“查看更多”链接来查看整个内容)。因此,当我获取前 200 个字符时,HTM Lmarkup 正在崩溃,因为我可能会错过一些已经开始的 html 标签的结束标签。我怎样才能摆脱这个问题?我知道我可以使用 strip_tags 删除所有 HTML 标记。但我想保持原样。我可以做些什么来解决这个问题吗?
in my PHP web application,I have a dataentry form where users will enter data using a rich text editor (FCKEditor i m using) and will be saving the Markup from the editor to the DB table.In another page i have to display the first 200 chars of the content (with View more link to view the entire thing). So when i m taking first 200 chars,the HTM Lmarkup is breaking because i may miss the closing tags of some of the html tags started already.How can i get rid of this ? I know i can use strip_tags to remove all HTML markup.But i wanna keep that as it is.Is there anything which i can do to solve this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过 HTMLTidy 运行它可能会有所帮助。例如,当您打开链接标签 (a) 但未关闭时,这可能有助于消除链接“出血”到下一个元素。如果您的脚本从标签中间剪切字符串(如“
最佳实践 imgo 是单独处理文本的“短”版本,只需让用户将其输入到单独的文本编辑器中即可。
Run it through HTMLTidy as that might help. For example, when you have link tag (a) opened but not closed, that might help to get rid of the link "bleed" to next element. You will still have issues if your script cuts the string from the middle of the tag, a la "<di". It's not fool-proof solution and i wouldn't rely on it.
The best practice imgo is to treat the "short" version of the text separately, just let the user enter it into separate text editor.