0
我的代碼如下結果:preg_grep不顯示用雙引號(「)
$escapedOperator = ":";
$operator['symbol'] = ":";
$string = 'title: "space before" and text breaks';
if(count(preg_grep('/\w["]*\s*'.$escapedOperator.'\s*["]*\w/',$string))){
$search = "/\s*".$escapedOperator."\s*/";
$string = preg_replace($search,$operator['symbol'],$string);
}else{
$string=str_replace($operator['symbol'],"",$string);
}
我得到的輸出:
title "space before" and text breaks
但我需要:
title:"space before" and text breaks
'preg_grep'需要數組作爲第二個參數,而不是字符串。也許你在尋找'preg_match'? –