tags:

views:

383

answers:

3

Hi frns,

Am using the strip_tags() to remove the HTML tags from one content . but i wants to remove the html (<DIV></DIV>,<P></P>,<SPAN></SPAN>) tags apart from the <img> tag and <a> , i don't want to remove the <img ><a> tag from that . but need to remove other all html tags from that content how can i do help me.

thanks

+3  A: 

If you want to strip all tags except for <img> tag, you can do like this:

strip_tags($your_text, '<img><a>');

The second parameter of the strip_tags function allows you to specify the allowed tags. You can specify more than one tags too.

Sarfraz
I think `strip_tags($text, '<a><img>')` is what Dam wants. Also, here's the documentation for `strip_tags`: http://php.net/strip_tags +1
Felix
@Felix: yes you are right, he added this after i posted my answer.
Sarfraz
+1  A: 
<?php
$text = '<p>Test paragraph.</p><img>sdfsdfsdfsd</img><!-- Comment --> <a href="#fragment">Other text</a>';
echo "\n";
echo strip_tags($text, '<p><a><img>');
?>
muruga
A: 

strip_tags has a lot of edge cases where it doesn't work. If you are using this on untrusted content, you'd be better off using HtmlPurifier instead.

troelskn