reference/pcre/functions/preg-replace.xml
62126c55f1c6ed444043e7272c4f9e233818a44b
...
...
@@ -21,6 +21,11 @@
21
21
<parameter>pattern</parameter> and replaces them with
22
22
<parameter>replacement</parameter>.
23
23
</para>
24
+
<para>
25
+
To match an exact string, rather than a pattern,
26
+
consider using <function>str_replace</function> or
27
+
<function>str_ireplace</function> instead of this function.
28
+
</para>
24
29
</refsect1>
25
30

26
31
<refsect1 role="parameters">
...
...
@@ -103,6 +108,10 @@
103
108
replace is performed on every entry of <parameter>subject</parameter>,
104
109
and the return value is an array as well.
105
110
</para>
111
+
<para>
112
+
If the <parameter>subject</parameter> array is associative, keys
113
+
will be preserved in the returned value.
114
+
</para>
106
115
</listitem>
107
116
</varlistentry>
108
117
<varlistentry>
...
...
@@ -296,6 +305,28 @@ xp***to
296
305
<function>preg_replace</function>.
297
306
</para>
298
307
</note>
308
+
<note>
309
+
<para>
310
+
When both <parameter>pattern</parameter> and <parameter>replacement</parameter> are
311
+
arrays, matching rules will operate sequentially. That is, the second <parameter>pattern</parameter>/<parameter>replacement</parameter>
312
+
pair will operate on the string that results from the first <parameter>pattern</parameter>/<parameter>replacement</parameter>
313
+
pair, not the original string. If you want to simulate replacements operating in parallel,
314
+
such as swapping two values, replace one pattern by an intermediary placeholder, then in a
315
+
later pair replace that intermediary placeholder with the desired replacement.
316
+
</para>
317
+
<informalexample>
318
+
<programlisting role="php">
319
+
<![CDATA[
320
+
<?php
321
+
$p = array('/a/', '/b/', '/c/');
322
+
$r = array('b', 'c', 'd');
323
+
print_r(preg_replace($p, $r, 'a'));
324
+
// prints d
325
+
?>
326
+
]]>
327
+
</programlisting>
328
+
</informalexample>
329
+
</note>
299
330
</refsect1>
300
331

301
332
<refsect1 role="seealso">
...
...
@@ -309,6 +340,7 @@ xp***to
309
340
<member><function>preg_replace_callback</function></member>
310
341
<member><function>preg_split</function></member>
311
342
<member><function>preg_last_error</function></member>
343
+
<member><function>str_replace</function></member>
312
344
</simplelist>
313
345
</para>
314
346
</refsect1>
315
347