如果文本中的单词与 中的单词兼容Array,则单词正在class添加。
$searchArray = array('settings all','print', 'sum', 'industry', ...); // total 50K words
function sanitize($string) {
global $searchArray;
$repl = array_map("dashReplace", $searchArray);
$string = str_replace($searchArray, $repl, $string);
return $string;
}
function dashReplace($str) {
return "<span class='txtOlg'>" . $str . "</span>";
}
echo sanitize($text);
结果:
Lorem Ipsum 只是印刷和排版所有行业的虚拟文本。
HTML 格式:
Lorem Ip<span class='txtOlg'>sum</span> is simply dummy text of the <span class='txtOlg'>print</span>ing and type<span class='txtOlg'>settings all</span> industry.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
如果单词中有匹配项,它会改变,但我不希望它改变。例如;
HTML 格式:
Lorem Ipsum is simply dummy text of the printing and typesettings all <span class='txtOlg'>industry</span>.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
如果它与单个单词兼容,我需要做什么来更改它?(不兼容单词)
MM们