我使用正则表达式来查找一些单词,并对单词/字符串做一些事情。
我的例子:
我不想用我找到的所有单词设置<strong>
标签:
$string = 'Hello, there is foo, after there is bar but now I need foo bar.'
$html = preg_replace('/(foo|bar)/', '<strong>$1</strong>', $string);
$html will be 'Hello, there is <strong>foo</strong>, after there is <strong>bar</strong> but now I need <strong>foo</strong> <strong>bar</strong>.'
而且我不想,如果他们是 1 个单词,然后是 1 个搜索的其他单词,那么结果:
'Hello, there is <strong>foo</strong>, after there is <strong>bar</strong> but now I need <strong>foo bar</strong>.'
如何修改我的正则表达式以获取我们之间的 2 个单词并在没有分隔标签的情况下对其进行处理?
谢谢