note 35265 deleted from function.preg-replace by vincent

From: Date: Tue, 26 Aug 2003 09:25:58 +0000
Subject: note 35265 deleted from function.preg-replace by vincent
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-55084@lists.php.net to get a copy of this message
Note Submitter: Alan Perry ---- 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!"

« previous php.notes (#55084) next »