我需要一个可以找到预定义关键字并使用该关键字标记所有行的脚本。
例:
我写了一个文本区域(在代码中使用预定义的关键字[funny,camera]
):
Can you give me the phone?
Phone have camera (mark all line)
I can take some photos
it will be funny (mark all line too)
我怎样才能完成这项任务?
发布于 2018-08-27 13:27:03
好的,我明白了,感谢大家的时间:
$whitelist = [
'med',
'boh'
];
$whitelistPregReplace = [];
foreach($whitelist as $word) {
$whitelistPregReplace[] = '~(.*)(' . $word . ')(.*)~im';
}
$text = preg_replace($whitelistPregReplace, '<span class="highlight">$1$2$3</span>', $text);
https://stackoverflow.com/questions/-100002414
复制相似问题