TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-17-2010, 11:18 PM   #1 (permalink)
The Wanderer
 
Join Date: Mar 2010
Posts: 9
Thanks: 2
dc2000 is on a distinguished road
Default Trouble using regexps to explude HTML tags

Hello:


My goal is to remove all HTML tags except the following:
// <b> and </b> = Bold;
// <i> and </i> = Italic;
// <u> and </u> = Underline;
// <ul> and </ul> = List;
// <ol> and </ol> = List;
// <li> and </li> = Bullet;
// <br> = Line Break;

So if I use the following line:
PHP Code:
$res preg_replace("/<\/?(b|i|u|ul|ol|li|br){1}>/i"""$raw); 
it removes the tags that I need and keeps the rest of them.

My question is how to "reverse" it?
dc2000 is offline  
Reply With Quote
Old 03-18-2010, 01:35 AM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

You're looking for ^

On a side note, your pattern will exclude any of those tags that include attributes such as a style, class or id attribute. Not sure if that matters to you or not, just thought I would give you the heads up.
delayedinsanity is offline  
Reply With Quote
Old 03-18-2010, 02:50 AM   #3 (permalink)
The Wanderer
 
Join Date: Mar 2010
Posts: 9
Thanks: 2
dc2000 is on a distinguished road
Default

Thanks. But where exactly do I put this ^?

And yes, again, all I need to let go through is the plain text and the following tags: <b>, </b>, <i>, </i>, <u>, </u>, <ul>, </ul>, <ol>, </ol>, <li>, </li>, <br>.

I'm sorry I'm not really good with regexs.
dc2000 is offline  
Reply With Quote
Old 03-18-2010, 04:59 AM   #4 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

~</?[^b|i|u|ul|ol|li|br]+?>~

^ when used in a range means anything but ...

Sorry I'd go into more detail but I'm making dinner.
delayedinsanity is offline  
Reply With Quote
Old 03-18-2010, 06:33 PM   #5 (permalink)
The Wanderer
 
Join Date: Mar 2010
Posts: 9
Thanks: 2
dc2000 is on a distinguished road
Default

Quote:
Originally Posted by delayedinsanity View Post
~</?[^b|i|u|ul|ol|li|br]+?>~

^ when used in a range means anything but ...

Sorry I'd go into more detail but I'm making dinner.
I tried your sample like this:
PHP Code:
$res preg_replace("/<\/?[^b|i|u|ul|ol|li|br]+?>/si"""$raw); 
and it still doesn't work. For example, it doesn't remove the following:

<a href="123">
or even
<le>
dc2000 is offline  
Reply With Quote
Old 03-18-2010, 08:04 PM   #6 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Dinner (especially steak dinner) trumps writing regular expressions.

It also trumps logical thought process. Such as using something more appropriate for the job at hand.

php Code:
// string strip_tags  (  string $str  [,  string $allowable_tags  ] )
$html = strip_tags( $html, '<b><i><u><ul><ol><li><br>' );
delayedinsanity is offline  
Reply With Quote
The Following User Says Thank You to delayedinsanity For This Useful Post:
dc2000 (03-18-2010)
Old 03-18-2010, 08:39 PM   #7 (permalink)
The Wanderer
 
Join Date: Mar 2010
Posts: 9
Thanks: 2
dc2000 is on a distinguished road
Default

Thanks! You're the man!
dc2000 is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Exciting Stuff in HTML 5! Wildhoney XHTML, HTML, CSS 20 02-17-2013 03:16 PM
Replace special chars not tags, php trigered by html Peuplarchie General 0 09-20-2009 02:32 PM
Wordpress tags some show some donīt EyeDentify General 0 01-19-2009 08:21 PM
Designing a tagging system Alan @ CIT Advanced PHP Programming 4 03-10-2008 03:25 PM
HTML tags xenon Advanced PHP Programming 3 02-02-2008 04:30 PM


All times are GMT. The time now is 01:26 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design