Php Remove only given html tags from string

by Subramanian 2014-07-15 15:57:28

Php Remove only given html tags from string :
PHP Function :
 
function stripeParticularTag($tags_to_strip,$str,$replace_with)
{ 
       foreach ($tags_to_strip as $tag) 
       {
               $str = preg_replace("$tag",$replace_with,$str);
       }
       return $str;
}


Eg:
$tags_to_strip = Array("p","font"  );
$str="<p>&nbsp;</p><b>GvSubhu</b><font>SS</font>"; 
$replace_with = ""; 

echo stripeParticularTag($tags_to_strip,$str,$replace_with);

O/p : <b>GvSubhu</b>
758
like
0
dislike
0
mail
flag

You must LOGIN to add comments