我想比较两个字符串并突出显示匹配连续的4个或更多单词。

当字符串中有双倍空格或换行时,出现问题,字符串未突出显示。

Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, 
graphic or web designs.
laying out print, graphic

预期产量:

Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in <span style="color:red">laying out print, 

graphic</span> or web designs.

PHP代码:

<?php
$str1 ="Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, 
graphic or web designs.";

$str2 = "/laying out print, graphic/iu";

echo preg_replace($str2, '<span style="color:red">$0</span>', $str1);
?>

注意:String1格式应相同。

$answer