Page 1 of 1

[solved] Need some regex help...

Posted: Tue Mar 22, 2005 10:04 am
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

Posted: Tue Mar 22, 2005 1:05 pm
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 :?

Posted: Tue Mar 22, 2005 1:13 pm
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