PHP从字符串中移除html标签 [英] PHP removing html tags from string
本文介绍了PHP从字符串中移除html标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有字符串:
I have string:
<p justify;"="">Verslo centrai Lietuvos nekilnojamojo turto plėtros asociacijos konkurse ...</p>
并希望删除标记 p>
and want want remove tag
<p justify;"=""></p>
我的代码:
my code:
$content = strip_tags($text, '<p>');
但是我得到空字符串: string(0)
,我做错了什么?
but i get empty string: string(0) ""
, what I do wrong ?
推荐答案
试着把它放在那里
$content = strip_tags($text);
或者你可以用像这样的正则表达式来做到这一点:
Or you can do it with regular expression like that:
$content = preg_replace('/<[^>]*>/', '', $text);
通过 $ content = strip_tags($ text,'< p> ');
您允许字符串中的< p>
标签。
By this $content = strip_tags($text, '<p>');
you are allowing the <p>
tag in the string.
欲了解更多信息,请参阅 http://php.net/manual/en/function.strip-tags .php
For more info see the link http://php.net/manual/en/function.strip-tags.php
这篇关于PHP从字符串中移除html标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文