Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Strip all html tags apart from a few.
Old 03-30-2010, 01:16 PM Strip all html tags apart from a few.
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Hi Guys,
Id like to strip all html tags from a string apart from things like
Bold , Underline or Href ?

Any ideas how to do this.

I know i can use strip_tags But this removes ALL
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
 
Register now for full access!
Old 03-31-2010, 05:43 AM Re: Strip all html tags apart from a few.
Super Talker

Posts: 139
Name: John Davis
Trades: 0
You wrong. strip_tags is perfect way. There is a second parameter - allowable_tags, you can use the optional second parameter to specify tags which should not be stripped.
http://php.net/strip_tags
__________________
»
Please login or register to view this content. Registration is FREE
- Interactive maps for websites
»
Please login or register to view this content. Registration is FREE
for web developers
MapMaster is offline
Reply With Quote
View Public Profile Visit MapMaster's homepage!
 
Old 03-31-2010, 11:03 AM Re: Strip all html tags apart from a few.
Andy Pugh's Avatar
Extreme Talker

Posts: 203
Name: Andy
Location: N.Ireland
Trades: 0
Hi Lynxus, just as a code example for what you need, you can do the following

PHP Code:
$yourstring 'hello <br/> how are you <p>yep</p> <strong>boldd</strong> <u>underlined</u> <a href="hello.php">hello</a>';
echo 
strip_tags($yourstring'<p><a><u>'); 
__________________

Please login or register to view this content. Registration is FREE
Andy Pugh is offline
Reply With Quote
View Public Profile
 
Old 03-31-2010, 11:05 AM Re: Strip all html tags apart from a few.
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Freakin awesome! i did not think it did it ( I thought, how cool it would be if it did! ) but didnt realise it actually did
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 04-01-2010, 05:34 AM Re: Strip all html tags apart from a few.
Experienced Talker

Posts: 41
Name: Adam B
Trades: 0
Perfect example of "always read the manual"
adam89 is offline
Reply With Quote
View Public Profile
 
Old 04-01-2010, 07:00 AM Re: Strip all html tags apart from a few.
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Quote:
Originally Posted by adam89 View Post
Perfect example of "always read the manual"
Well yeah i spose it is

I was sure it wouldn't do what i wanted, So didn't bother lol.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 04-01-2010, 09:04 AM Re: Strip all html tags apart from a few.
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
May I ask how you are going to be using it? You need to be careful, because the second argument to strip_tags will allow certain tags, but will also allow all attributes on those tags. If you're using this to sanitize user input you'll need to implement a custom means of removing certain attributes if this is sanitizing publicly inputted information. Stuff like onmouseover and onclick can be quite bad for your page if it is injected by a random person.
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Reply     « Reply to Strip all html tags apart from a few.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25104 seconds with 12 queries