本文介绍了用于HTML标签的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在执行以下操作:

 < ;?$ text = preg_replace("/&p;(.*?)<\/p>/","$ 1< br>","$ text");?> 

因此,我可以删除< p> 标记,并在字符串的末尾放置一个空格(这是用于页面样式).

这完全适用于< p>某事</p>" .

但是,带有如下文字:

由Cicero在45 BC/h3中写成的"de Finibus Bonorum et Malorum"的第1.10.32节.< p>"Sed ut perspiciatis unde omnis iste natus错误坐在voluptatem被告doloremque laudantium,totam rem aperiam,eaque ipsa quae ab illo inventore和准的建筑设计师Beate uttas avita setata volt taquit quitaupaFugit,sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.Neque porro quisquam est,qui dolorem ipsum quia dolor sitome,consectetur,adipisci velit,sed quia non quaquam equaupe quaute quaute quaute quaute quaute quaut equa quaute quaut equa quaute quaut equa quaut equa quaut equa quaut equa quaut equa quaut equa quaut e quaqua et al quaqua equa quaut e quaqua et al quaqua equa quaut e qua qua qua qua qua qua qua qua qua qua qua qua qua qua n最低限度的验证,实验室的无意识的锻炼,实验室的液体化的结果,还是液体中的液体的恢复,在液体中的感觉是什么,而液体的变化又是什么,液体化后的结果,"液体化后的现象,,",,",,",",",",",","",","",",",",","了,,"了.《.............................................................................,..............................</p>

我从Lorem Ipsum(lipsum.com)页面上获取的信息无效,并且我不知道为什么.

在某种程度上相关的注释上(并且我不确定它是否足够相关以保持相同的问题,但这可能有助于解决该问题),是否有任何功能或方法可以自动删除这些标记的每个javascript代码段可以在里面吗?例如

 < p onmouseover ="alert('hello');"> 

感谢您的帮助.

解决方案

尝试以下php调用:

  $ text = preg_replace('〜< p \ b [^>] *>(.*?)</p>〜smi',"$ 1< br>",$ text); 

它将处理忽略的大小写匹配( p P )以及多行匹配.

I'm doing the following:

<?
$text = preg_replace ("/<p>(.*?)<\/p>/", "$1<br>", "$text");
?>

So I can get rid of <p> tags and place a space at the end of the string (this is for styling of the page).

This works for "<p>Something</p>" perfectly.

However, with text like:

<h3>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC</h3>
<p>"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</p>

That I took from the Lorem Ipsum (lipsum.com) page, it doesn't work, and I don't have a clue why.

On a somehow related note (and I'm not sure if it's related enough to keep in the same question, but it could help towards this problem), is there any function or way to automatically remove every javascript snippet that these tags could have in them?e.g

<p onmouseover="alert('hello');">

Thanks for any help.

解决方案

Try this php call:

$text = preg_replace('~<p\b[^>]*>(.*?)</p>~smi', "$1<br>", $text);

It will handle ignore case matches (p and P) as well as multi-line matches.

这篇关于用于HTML标签的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-02 01:47