For Programmers: Free Programming Magazines  


Home > Archive > PHP Documentation > October 2006 > cvs: phpdoc /en/reference/strings/functions str-replace.xml









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author cvs: phpdoc /en/reference/strings/functions str-replace.xml
Dave Barr

2006-10-15, 3:56 am

dave Sun Oct 15 05:06:13 2006 UTC

Modified files:
/phpdoc/en/reference/strings/functions str-replace.xml
Log:
- Document order of replacement (ie. first to last) when search/replace
parameters are arrays. Fixes #38463.


http://cvs.php.net/viewvc.cgi/phpdo...0&diff_format=u
Index: phpdoc/en/reference/strings/functions/str-replace.xml
diff -u phpdoc/en/reference/strings/functions/str-replace.xml:1.19 phpdoc/en/reference/strings/functions/str-replace.xml:1.20
--- phpdoc/en/reference/strings/functions/str-replace.xml:1.19 Fri Aug 11 17:15:27 2006
+++ phpdoc/en/reference/strings/functions/str-replace.xml Sun Oct 15 05:06:12 2006
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.19 $ -->
+<!-- $Revision: 1.20 $ -->
<!-- splitted from ./en/functions/strings.xml, last change in rev 1.2 -->
<refentry id="function.str-replace">
<refnamediv>
@@ -59,7 +59,11 @@
is an array and <parameter>replace</parameter> is a string, then
this replacement string is used for every value of
<parameter>search</parameter>. The converse would not make sense,
- though.
+ though.
+ </para>
+ <para>
+ If <parameter>search</parameter> or <parameter>replace</parameter>
+ are arrays, their elements are processed first to last.
</para>
<para>
<example>
@@ -84,6 +88,14 @@
// 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 = '<br />';
+// Processes \r\n's first so they aren't converted twice.
+$newstr = str_replace($order, $replace, $str);
+
?>
]]>
</programlisting>
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com