Home  >  Article  >  Backend Development  >  正则表达式 - php如何过滤掉字符串中的某个标签?

正则表达式 - php如何过滤掉字符串中的某个标签?

WBOY
WBOYOriginal
2016-06-06 20:14:081284browse

我从富文本编辑器中得到的值最外层被

标签包裹,
例如
<code>$res=$_POST['content'];</code>

$res是我获得的内容,但里面有p标签,我不会正则表达式,要怎么过滤掉最外层的P标签再放入数据库。

回复内容:

我从富文本编辑器中得到的值最外层被

标签包裹,
例如
<code>$res=$_POST['content'];</code>

$res是我获得的内容,但里面有p标签,我不会正则表达式,要怎么过滤掉最外层的P标签再放入数据库。

strip_tags()

strip_tags() 函数剥去字符串中的 HTML、XML 以及 PHP 的标签。
语法
strip_tags(string,allow)
参数 描述
string 必需。规定要检查的字符串。
allow 可选。规定允许的标签。这些标签不会被删除。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn