时间:2021-07-01 10:21:17 帮助过:23人阅读
function highlight_words($str, $words, $color = '#FFFF00') { if(is_array($words)) { foreach($words as $k => $word) { $pattern[$k] = "/\b($word)\b/is"; $replace[$k] = '\\1'; } } else { $pattern = "/\b($words)\b/is"; $replace = '\\1'; } return preg_replace($pattern,$replace,$str); }