I have an array of words which I am using to highlight words in a string, some of the words however might appear as part of a phrase, and so I would like the phrase to take precedence over the single word in the highlight:
For example:
$seo = ['apple', 'apple tree', 'orchard'];
$description = "In my orchard I have a large Apple Tree";
Desired effect:
In my <strong>orchard</strong> I have a large <strong>Apple Tree</strong>
In my own first attempt, I looped through the array running preg_replace() against the string, but I am getting nested highlights like this <strong><strong>Apple</strong> Tree</strong>.