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

sql - Postgresql error: "failed to find conversion function from unknown to text" -

javascript - Why in IE loading image not show at center bottom of page? -

Phantomjs login, redirect and render page after pageLoad finishes -