note 78395 rejected from function.preg-replace by felipe

From: Date: Sun, 16 Dec 2007 12:55:38 +0000
Subject: note 78395 rejected from function.preg-replace by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-133706@lists.php.net to get a copy of this message
Note Submitter: djurredenboer at hotmail dot com ---- I found something strange <?php $string = 'The quick brown fox jumped over the lazy dog.'; $patterns[0] = '/quick/'; $patterns[1] = '/brown/'; $patterns[2] = '/fox/'; $replacements[2] = 'bear'; $replacements[1] = 'black'; $replacements[0] = 'slow'; echo preg_replace($patterns, $replacements, $string); ?> Output The bear black slow jumped over the lazy dog. But when you swap the replacements like $replacements[0] = 'slow'; $replacements[2] = 'bear'; $replacements[1] = 'black'; you get The slow bear black jumped over the lazy dog.

« previous php.notes (#133706) next »