[solved] Need some regex help...

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
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

[solved] Need some regex help...

Post by Burrito »

I have a div that has an onBlur event attached to it but my event keeps running when I mouseover <p>'s and <a>'s etc. This is obvious to me why, but I dont' want it to happen.

I need to prevent that from happening so I came up with using another event on all of those "child" elements that calls event.cancelBubble = true;. I know I know...IE only, but that's the only crowd I need to worry about here.

My issue then becomes adding an onmouseout event to those elements (that are dynamically inserted to my div). I wanted to just do a replace for all ">" with "onMouseOut="event.cancelBubble=true;" but that would also grab the end tags as well. So I'm goign to need some kind of regex to ensure that I don't replace the ">" on the end tags. But as you may alraedy know...Feyd I knwo you do, I'm a total friggin' regex wannabe.

can someone help me out with this?

thx,

Burr
Last edited by Burrito on Tue Mar 22, 2005 1:14 pm, edited 1 time in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

So this:

Code: Select all

<div onBlur=&quote;something()&quote;>
    Text here, yada yada yada<br>
    Dumty dumty dum.....<br>
    <a href=&quote;*****&quote;>Oh dear I've hit a link</a><p>
    No worries a regex could fix it!</p>
</div>
Would become what exactly?

Code: Select all

<div onBlur=&quote;something()&quote;>
    Text here, yada yada yada<br>
    Dumty dumty dum.....<br>
    <a href=&quote;*****&quote; onMouseout=&quote;event.cancelBubble=true&quote;>Oh dear I've hit a link</a><p onMouseout=&quote;event.cancelBubble=true&quote;>
    No worries a regex could fix it!</p>
</div>
I'm sure you don't need to apply it to all the <BR>'s and <b>'s and <i>'s etc do you? It's be complex to avoid it though.

EDIT: If ">" really IS all that you want to replace that would be easier with str_replace() surely? - Just use strrchr() to get the ending ">" and remove it first :?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

d11wtq wrote:So this:

EDIT: If ">" really IS all that you want to replace that would be easier with str_replace() surely? :?
Indeed it would, but I don't want to replace the end tags.

Ex:

Code: Select all

<span id="4b">this is in my span</span>
would become

Code: Select all

<span id="4b" onMouseOut="mystuff()">this is in my span</span onMouseOut="mystuff()">
Feyd has already helped me with this...sorry I forgot to update this thread:

here's what he came up with:

Code: Select all

$newstuf = preg_replace('#(<\s*(?!/).*?)>#','\\1 onMouseOut="event.cancelBubble=true">',$gtdates['eventdesc']);
and no, I don't care about <br>'s etc.

thanks,

Burrito
Post Reply