note 35265 added to function.preg-replace

From: Date: Mon, 25 Aug 2003 22:17:35 +0000
Subject: note 35265 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-55066@lists.php.net to get a copy of this message
The previous statement is true, but as stated in Example 2 above, if you do a ksort before the replacement, then it works fine. Changing the second listing to this: <?php $string = "The order of setting the array is very important!"; $pattern=array(); $replacement=array(); $pattern[1] = "/order/"; $pattern[2] = "/of/"; $pattern[0] = "/The/"; $pattern[3] = "/setting/"; $pattern[4] = "/the/"; $pattern[5] = "/array/"; $pattern[6] = "/is/"; $replacement[5] = "ARRAY"; $replacement[1] = "ORDER"; $replacement[2] = "OF"; $replacement[0] = "tHE"; $replacement[3] = "SETTING"; $replacement[4] = "THE"; $replacement[6] = "IS"; // *** NEW LINES ksort($pattern); ksort($replacement); // *** END NEW LINES echo preg_replace($pattern, $replacement, $string); ?> Gives you the string in the correct order: "tHE ORDER OF SETTING THE ARRAY IS very important!" ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35265 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35265&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35265&report=yes

« previous php.notes (#55066) next »