I’ve got a special case where I am making phrase replacements and I need to keep my word boundaries and omit any actions from taking place on my content inside header tags (<h1><h2><h3><h4><h5>).
Here’s what I got so far, and it is saying ignore phrases if they fall after a > or a -, which prevents URLS and Hyperlinks from being edited too.
preg_replace("/[^\>\.-]\b{$keywords}\b/i"," <a href='$url' target='$target'>$keywords</a>
So the regex needs to :
- Honor word boundaries
- Ignore phrases within header tags, and hyperlinks.
- Treat -(dashes) as a boundary too, which \b does not seem to do.
Any advise?
I found a solution for the header tags with a lookahead.
I tried to find a solution for text in alt and title tags using the look behind feature but could not get it to work without breaking the regex. It seems everytime I used a .+ or a (.*?) in the lookbehind it broke it.