![](/img/trans.png)
[英]How to parse HTML using PHP and display as plain text all tags within <code></code> except <br> tag
[英]Regex to find text outside HTML tags and then replace <br> tag with <p> using PHP
我正在使用HTML5 WYSIWYG编辑器,该编辑器似乎没有自动插入段落标签。 但是,它确实插入了br和h1,h2等。生成的文本的基本示例如下所示:
<h1>This is a header</h1>This should be a stand alone paragraph<br><br>This paragraph should split<br>into two lines.
我想知道是否有可能将所有未包含在打开和关闭标记中的内容放入一个段落中,然后用</p>
<p>
替换double br来生成此代码:
<h1>This is a header</h1><p>This should be a stand alone paragraph</p><p>This paragraph should split<br>into two lines.</p>
先谢谢您的帮助。
只要您输入的文本与您提供的示例具有相同的结构: <h1>This is a header</h1>This should be a stand alone paragraph<br><br>This paragraph should split<br>into two lines.
然后,您可以使用此正则表达式:
^(.*<\/h1>)([^<]+)(<br>\s*<br>)(.*)$
并替换为: \\1<p>\\2</p><p>\\4</p>
这是一个有效的演示
应该很容易做到。 我将采取的步骤:
<p></p>
换行 <br><br>
替换为<p></p>
另外,除了正则表达式外,在尝试确定标记中包含哪些内容以及不包含哪些内容时,也可以使用它: http : //api.jquery.com/jQuery.parseHTML/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.