Jump to content

RegEx to determine if a word is inside anchor tags


brianlange

Recommended Posts

Unless you're reading in a plain text file, there will always be HTML tags around your chosen word; unless you really mean something much more specific like literally, only, around the word itself?  Could you elaborate a little more on precisely what you want to accept as matching and what you want to disallow from matching?

 

Also, if you've made a start on matching the word but cannot quite adapt that to looking for tags, post up any regex that you have at the moment for us to help you to adapt it. :)

It would be sufficient to determine whether the word is in anchor tags.

Right now I have an array of regular expressions and an array of replacement strings.

I use preg_replace to perform the replacement.

I have about 700 words in my search array.

$search = array("/\bAAA tenant\b/i","/\babandonment\b/i");
$replacement = array('<a href="/words/aaa-tenant">AAA tenant</a>','<a href="/words/abandonment">abandonment</a>');
preg_replace($_search, $_replacement, $content);

 

 

 

 

-Brian

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.