How can I strip certain tags between certan points?

07-23-04, 06:05 PM
|
 |
Community Liaison
|
|
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
|
|
How can I strip certain tags between certan points?
Ok, this is for a client of mine. This is the way they'd like it, and I'm so-so with regex's...
The program I wrote for them adds text to pages. With each page they are able to specify whether they want carriage returns to insert break tags or whether they want to insert break tags themselves.
Well, I have this client that wants it to be able to add tags that will allow them to turn on break tags, yet add tags that will remove any break tags in between.
Here's waht I'm talking about : You see what I mean? They want each new line to add a break tag, but they'd like to have any break tags between the <nobr></nobr> tags stripped out, or not have them inserted to begin with (for exactly that purpose: html tags, etc...).
Any regex experts wanna have a go at it? 
|

07-23-04, 07:51 PM
|
|
Newbie Coder
|
|
Join Date: Feb 2004
Location: Earth
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You could try writing a function and replacing tags with the function result. For example:
Now; I dunno if you get it but there's an idea for ya.
__________________
-- my bad lol
|

07-24-04, 07:47 AM
|
 |
Community Liaison
|
|
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
|
|
Ehhh, not sure if you understand what I meant, because I don't understand what that's supposed to do.
I got it figured out anyhow, just had to crack my head open and apply myself. Thanks though:
Last edited by Keith; 07-24-04 at 08:31 AM.
|

07-24-04, 08:23 AM
|
|
Wannabe Coder
|
|
Join Date: Jun 2004
Location: php[dot]net
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Here we go. Consider the tag which disallow line break is [nobr]. Based on your problem, I think we have to do double regex check. First, to strip the line break in the tag and then to strip [nobr] tag from it.
Here is an example code:
I don't know whether PHP can call function preg_replace within another preg_replace function. If it could, the above code should be optimised.
|

07-24-04, 08:27 AM
|
|
Wannabe Coder
|
|
Join Date: Jun 2004
Location: php[dot]net
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
|
Originally Posted by Keith
Ehhh, not sure if you understand what I men, because I don't understand what that's supposed to do.
I got it figured out anyhow, just had to crack my head open and apply myself. Thanks though:
|
Oh you've found it. Anyway, str_replace wouldn't substitute <BR>, <BR /> or <br>.
|

07-24-04, 08:30 AM
|
 |
Community Liaison
|
|
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
|
|
Yep, I use the XHTML break tag anyhow (nl2br() function to be more specific). I wasn't sure either if preg_replace could be used inside preg_replace... but on your suggestion I tried it and it works like a charm for both <br> as well as <br /> tags:
|

07-24-04, 08:40 AM
|
|
Wannabe Coder
|
|
Join Date: Jun 2004
Location: php[dot]net
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The optimised code should be:
|

07-24-04, 08:44 AM
|
|
Wannabe Coder
|
|
Join Date: Jun 2004
Location: php[dot]net
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
haha... finally it's done. thank you also. now i know that i can call multiple preg_replace which can save lot of my work... thanks again..
|

07-24-04, 01:43 PM
|
 |
Community Liaison
|
|
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
|
|
No problem, thanks for the optimization.  I still have a lot to learn regarding regex's.
|

03-25-05, 01:19 AM
|
|
New Member
|
|
Join Date: Mar 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Optimization ?
a good optimization at this point would rather be to put these calls on separate lines since it doesn't accelerate nor lighten the process to put this in a single line. And what you'll get from this ? Tell me what if not a hardened way to maintain your code... 
Last edited by adoxe; 03-25-05 at 01:25 AM.
Reason: talkin' about optimization...
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|