Php.net過這樣的preg_replace片斷如何使用模式是一個數組(PHP)的preg_match
$string = 'The quick brown fox jumped over the lazy dog.';
$patterns = array();
$patterns[0] = '/quick/';
$patterns[1] = '/brown/';
$patterns[2] = '/fox/';
$replacements = array();
$replacements[2] = 'bear';
$replacements[1] = 'black';
$replacements[0] = 'slow';
echo preg_replace($patterns, $replacements, $string);
有沒有一種方法,以便做這樣的事情
運行$圖案的preg_match如果preg_match在$ string中找到,那麼preg_replace else回聲沒有匹配找到
謝謝。
試過了更早。不起作用。很確定你可以放棄preg_replace的回聲。無法使用或不使用它。 – stevenmw
編輯我的答案;) –
這仍然不起作用。每個模式需要像'/ quick /'我想盡可能保持我的數組。也許我可以使用implode或foreach? – stevenmw