php - Preventing Preg_Replace from changing <A> element contents -


i have link replacement function wrote finds keywords , turns said key words links related content.

it has been working far, except on occasion, link adds in contains keyword.

this issue has resulted in keywords being turned mess of hmtl code , unworking links wherever occurrence happens.

what plan 1 final check before replace verify if keyword within element .

is possible determine if content between tags? if so, how done?

these current patterns using find keywords.

$pattern = "/\b $kw \b/"; $pattern2 = "/\b $kw. \b/"; $pattern3 = "/\b $kw, \b/"; 

firstly patterns can merged one:

$pattern = "/\b $kw[.,]? \b/"; 

i question whitespaces there. don't want them.

$pattern = "/\b$kw[.,]?\b/"; 

and voodoo black magic of regex doom!

$pattern = "/<a\b.*?<\/a>(*skip)(*fail)|\b$kw[.,]?\b/"; 

but beware the pony , consider using parser instead.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -