Page 1 of 1

Removing html tags but not all

Posted: Fri Nov 16, 2007 6:02 am
by Addos
Hi,
I need to remove some html tags and can successfully do this with the code below.

Code: Select all

<?PHP  $cleaned_up = trim(strip_tags('<span> Hi there </span>'));
 echo $cleaned_up ?>
However I want to be able to leave in some html tags for example I like to be able to leave this in the code below <table><tr> <td? Hi there </td> </tr> </table> while removing the <span> tags etc.

Code: Select all

<?PHP  $cleaned_up = trim(strip_tags('<span> <table><tr> <td? Hi there </td> </tr> </table></span>'));
 echo $cleaned_up ?>
Can this be done?
Thanks for any help
B

Posted: Fri Nov 16, 2007 6:07 am
by s.dot
You can specify which tags you don't want to strip using the second parameter of strip_tags()

Code: Select all

strip_tags($text, '<table><tr><td>');