开发者

preg_replace html tags

I would like to delete all html tags (including their attributes such as class, src, id, etc.) on a string but I would like to retain <ul>,<li> and <br开发者_运维技巧 /> tags. How will I accomplish this?

Any suggestion would be greatly appreciated.

Thanks!


Use strip_tags() and pass in allowable tags. No need to re-invent the wheel. There are some security concerns with this method which might prevent you from using it. Please consider @Denis' answer if this is the case.


You can use a library such as html purifier:

http://htmlpurifier.org/

Be wary of using strip_tags() with an argument:

Is strip_tags() vulnerable to scripting attacks?

http://htmlpurifier.org/comparison


http://us.php.net/manual/en/function.strip-tags.php

strip_tags($text, '<ul><li><br>');


There you go, bro

http://us.php.net/manual/en/function.strip-tags.php

$text = strip_tags($text, '<ul><li><br>');

Do not use preg_replace, it cost u lot memory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜