Removing html tags but not all

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

Removing html tags but not all

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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>');
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply