0
我用preg_replace替換字符串時出現問題。PHP preg_replace多個單詞
function addClass($search, $string) {
return preg_replace("/\b($search)\b/", "<div class=mark>$1</div>", $string);
}
$string = "We won again";
$result = addClass("We", $string);
output ---> <div class=mark>We</div> won again
我想爲多個字符串製作$search
。
$string = "We won again";
$result = addClass(array("We", "again"), $string);
output ---> <div class=mark>We</div> won <div class=mark>again</div>
如何實現多個搜索字符串放入數組?
在此先感謝...
如何使用它?數組(「我們」,「贏」)不工作 –
working-working - https://eval.in/588758 – splash58
啊,我的壞。我輸入「我們」而不是「我們」,如何使其不區分大小寫? –