reference/pcre/functions/preg-replace.xml
62126c55f1c6ed444043e7272c4f9e233818a44b
...
...
@@ -9,18 +9,23 @@
9
9
<refsect1 role="description">
10
10
&reftitle.description;
11
11
<methodsynopsis>
12
-
<type>mixed</type><methodname>preg_replace</methodname>
13
-
<methodparam><type>mixed</type><parameter>pattern</parameter></methodparam>
14
-
<methodparam><type>mixed</type><parameter>replacement</parameter></methodparam>
15
-
<methodparam><type>mixed</type><parameter>subject</parameter></methodparam>
12
+
<type class="union"><type>string</type><type>array</type><type>null</type></type><methodname>preg_replace</methodname>
13
+
<methodparam><type class="union"><type>string</type><type>array</type></type><parameter>pattern</parameter></methodparam>
14
+
<methodparam><type class="union"><type>string</type><type>array</type></type><parameter>replacement</parameter></methodparam>
15
+
<methodparam><type class="union"><type>string</type><type>array</type></type><parameter>subject</parameter></methodparam>
16
16
<methodparam choice="opt"><type>int</type><parameter>limit</parameter><initializer>-1</initializer></methodparam>
17
-
<methodparam choice="opt"><type>int</type><parameter role="reference">count</parameter></methodparam>
17
+
<methodparam choice="opt"><type>int</type><parameter role="reference">count</parameter><initializer>&null;</initializer></methodparam>
18
18
</methodsynopsis>
19
19
<para>
20
20
Searches <parameter>subject</parameter> for matches to
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>
...
...
@@ -145,10 +154,10 @@
145
154
<refsect1 role="errors">
146
155
&reftitle.errors;
147
156
<para>
148
-
As of PHP 5.5.0 <constant>E_DEPRECATED</constant> level error is emitted when
149
-
passing in the "\e" modifier. As of PHP 7.0.0 using the "\e" modifier is an error;
157
+
Using the "\e" modifier is an error;
150
158
an <constant>E_WARNING</constant> is emitted in this case.
151
159
</para>
160
+
&pcre.pattern.warning;
152
161
</refsect1>
153
162

154
163
<refsect1 role="examples">
...
...
@@ -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,11 +340,11 @@ 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
</refentry>
316
-

317
348
<!-- Keep this comment at the end of the file
318
349
Local variables:
319
350
mode: sgml
320
351