由于误解,我已经重新格式化了这个问题,这对我和问题产生了不适感,不是故意的,对此我表示歉意。
我有一个单词数组,用于突出显示字符串中的单词,但是某些单词可能会作为短语的一部分出现,因此我希望该短语在突出显示部分中占上风:
例如:
// Array
$seo = array("apple, apple tree, orchard");
// String
$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>
在我自己的第一次尝试中,我遍历数组,对字符串运行preg_replace,但是我得到了像这样的嵌套突出显示<strong><strong>Apple</strong> Tree</strong>
在此先感谢您的协助
斯图