From 3e2879c046b40f2cbc6affbe27c754e2b95960a0 Mon Sep 17 00:00:00 2001 From: Dave Barr Date: Sun, 15 Oct 2006 05:06:12 +0000 Subject: [PATCH] - Document order of replacement (ie. first to last) when search/replace parameters are arrays. Fixes #38463. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@221791 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/strings/functions/str-replace.xml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/reference/strings/functions/str-replace.xml b/reference/strings/functions/str-replace.xml index 7804fb7a18..2f2e44d6f4 100644 --- a/reference/strings/functions/str-replace.xml +++ b/reference/strings/functions/str-replace.xml @@ -1,5 +1,5 @@ - + @@ -59,7 +59,11 @@ is an array and replace is a string, then this replacement string is used for every value of search. The converse would not make sense, - though. + though. + + + If search or replace + are arrays, their elements are processed first to last. @@ -84,6 +88,14 @@ $newphrase = str_replace($healthy, $yummy, $phrase); // Use of the count parameter is available as of PHP 5.0.0 $str = str_replace("ll", "", "good golly miss molly!", $count); echo $count; // 2 + +// Order of replacement +$str = "Line 1\nLine 2\rLine 3\r\nLine 4\n"; +$order = array("\r\n", "\n", "\r"); +$replace = '
'; +// Processes \r\n's first so they aren't converted twice. +$newstr = str_replace($order, $replace, $str); + ?> ]]>