PHP 自动套用段落格式标签
这是一个相当基本的问题,但我只找到了三个答案。我想对可能包含也可能不包含其他 html 元素的未格式化内容进行自动段落标记。两个不错的函数是 wordpress wpautop、HTMLPurifier AutoFormat.AutoParagraph 以及最后一些随机的addParagraphsNew。然而,第一个与我的应用程序许可证不兼容,第二个不在段落标签内添加换行符,第三个是不稳定的。
有谁知道商业上合适的许可脚本,允许将具有换行符和双换行符的html内容转换为
和
标签?
我相信 HTMLPurifier 选项可能是我侵入 AutoFormat.AutoParagraph 插件以使其添加换行符的最佳方法,但我希望能稍微简单一些。我知道很懒。
This is a fairly basic question however I've only ever managed to find three answers. I want to autoparagraph unformatted content that may or may not contain other html elements. The two good to go functions are the wordpress wpautop, HTMLPurifier AutoFormat.AutoParagraph and lastly some random addParagraphsNew. However the first is incompatible with my applications license, the second doesn't add line breaks within the paragraph tags and the third is flakey.
Does anyone know on a commercially suitable licensed script that allows html content that has line breaks and double line breaks to be converted into <br />
and <p>
tags?
I believe the HTMLPurifier option is probably the best way to go my hacking into the AutoFormat.AutoParagraph plugin to get it to add line breaks but I was hoping was something slightly easier. Lazy I know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,你可以自己破解它(如果我正确理解你需要什么),
这实际上会输出:
注意它现在如何丢失所有换行符等......
well you could hack it yourself (if I understand what you need correctly)
That will actually output this:
Notice how it's missing all the newlines etc. now...
这是一个 JavaScript 解决方案,它将向行添加段落标签。它将忽略空行、标题、图像、列表和代码块内的行。
Here is a JavaScript solution that will add paragraph tags to lines. It will ignore lines that are empty, headers, images, lists and within code blocks.