reference/pcre/functions/preg-replace.xml
31b22987dd66a0251de914029b9f1b4c377bf9af
...
...
@@ -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>
...
...
@@ -148,6 +157,7 @@
148
157
Using the "\e" modifier is an error;
149
158
an <constant>E_WARNING</constant> is emitted in this case.
150
159
</para>
160
+
&pcre.pattern.warning;
151
161
</refsect1>
152
162

153
163
<refsect1 role="examples">
...
...
@@ -295,6 +305,28 @@ xp***to
295
305
<function>preg_replace</function>.
296
306
</para>
297
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
+
<example>
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
+
</example>
329
+
</note>
298
330
</refsect1>
299
331

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