Forum Moderators: coopster

Message Too Old, No Replies

regular expression to find a specific word in a body of text?

while also making sure it is not a linked word already

         

cuce

5:10 pm on Aug 14, 2006 (gmt 0)

10+ Year Member



What would be the regular expression to find a specific word in a body of text, while also making sure it is not a linked word already?

cuce

9:34 pm on Aug 14, 2006 (gmt 0)

10+ Year Member



Here's my best attempt:

if(!eregi("^<[^>]*>".$val."</[^>]*>$", $content)){}

Doesn't quite work.

If my text says this:

blah blah blah <a href="some place">web</a> blah blah blah blah
web blah blah

I want the second occurence to be surrounded with the new link pointing to the dynamically generated url but not add another link inside a link to the first occurence.

cuce

3:55 pm on Aug 15, 2006 (gmt 0)

10+ Year Member



anybody?

coopster

1:44 pm on Aug 22, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



How about if you make sure the word is not already directly preceded by a greater-than sign ">" and also not directly followed by a closing </a> element?