reference/strings/functions/strtr.xml
2a7c919451f9a536431ba2117f8f90ae814c1c5f
...
...
@@ -1,6 +1,6 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
-
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.strtr" xmlns:xlink="http://www.w3.org/1999/xlink">
3
+
<refentry xml:id="function.strtr" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
4
4
<refnamediv>
5
5
<refname>strtr</refname>
6
6
<refpurpose>Translate characters or replace substrings</refpurpose>
...
...
@@ -10,18 +10,19 @@
10
10
&reftitle.description;
11
11
<methodsynopsis>
12
12
<type>string</type><methodname>strtr</methodname>
13
-
<methodparam><type>string</type><parameter>str</parameter></methodparam>
13
+
<methodparam><type>string</type><parameter>string</parameter></methodparam>
14
14
<methodparam><type>string</type><parameter>from</parameter></methodparam>
15
15
<methodparam><type>string</type><parameter>to</parameter></methodparam>
16
16
</methodsynopsis>
17
+
<simpara>Alternative signature (not supported with named arguments):</simpara>
17
18
<methodsynopsis>
18
19
<type>string</type><methodname>strtr</methodname>
19
-
<methodparam><type>string</type><parameter>str</parameter></methodparam>
20
+
<methodparam><type>string</type><parameter>string</parameter></methodparam>
20
21
<methodparam><type>array</type><parameter>replace_pairs</parameter></methodparam>
21
22
</methodsynopsis>
22
23
<para>
23
24
If given three arguments, this function returns a copy of
24
-
<parameter>str</parameter> where all occurrences of each (single-byte)
25
+
<parameter>string</parameter> where all occurrences of each (single-byte)
25
26
character in <parameter>from</parameter> have been translated to the
26
27
corresponding character in <parameter>to</parameter>, i.e., every
27
28
occurrence of <literal>$from[$n]</literal> has been replaced with
...
...
@@ -31,12 +32,12 @@
31
32
<para>
32
33
If <parameter>from</parameter> and <parameter>to</parameter> have
33
34
different lengths, the extra characters in the longer of the two
34
-
are ignored. The length of <parameter>str</parameter> will be the same as
35
+
are ignored. The length of <parameter>string</parameter> will be the same as
35
36
the return value's.
36
37
</para>
37
38
<para>
38
39
If given two arguments, the second should be an <type>array</type> in the
39
-
form <literal>array('from' => 'to', ...)</literal>. The return value is
40
+
form <literal>array('from' =&gt; 'to', ...)</literal>. The return value is
40
41
a <type>string</type> where all the occurrences of the array keys have been
41
42
replaced by the corresponding values. The longest keys will be tried first.
42
43
Once a substring has been replaced, its new value will not be searched
...
...
@@ -45,7 +46,7 @@
45
46
<para>
46
47
In this case, the keys and the values may have any length, provided that
47
48
there is no empty key; additionally, the length of the return value may
48
-
differ from that of <parameter>str</parameter>.
49
+
differ from that of <parameter>string</parameter>.
49
50
However, this function will be the most efficient when all the keys have the
50
51
same size.
51
52
</para>
...
...
@@ -56,7 +57,7 @@
56
57
<para>
57
58
<variablelist>
58
59
<varlistentry>
59
-
<term><parameter>str</parameter></term>
60
+
<term><parameter>string</parameter></term>
60
61
<listitem>
61
62
<para>
62
63
The <type>string</type> being translated.
...
...
@@ -85,7 +86,12 @@
85
86
<para>
86
87
The <parameter>replace_pairs</parameter> parameter may be used instead of
87
88
<parameter>to</parameter> and <parameter>from</parameter>, in which case it's an
88
-
<type>array</type> in the form <literal>array('from' => 'to', ...)</literal>.
89
+
<type>array</type> in the form <literal>array('from' =&gt; 'to', ...)</literal>.
90
+
</para>
91
+
<para>
92
+
If <parameter>replace_pairs</parameter> contains a key which is an empty
93
+
<type>string</type> (<literal>""</literal>), the element is ignored;
94
+
as of PHP 8.0.0 <constant>E_WARNING</constant> is raised in this case.
89
95
</para>
90
96
</listitem>
91
97
</varlistentry>
...
...
@@ -98,13 +104,6 @@
98
104
<para>
99
105
Returns the translated <type>string</type>.
100
106
</para>
101
-
<para>
102
-
If <parameter>replace_pairs</parameter> contains a key which
103
-
is an empty <type>string</type> (<literal>""</literal>),
104
-
&false; will be returned. If the <parameter>str</parameter> is not a scalar
105
-
then it is not typecasted into a string, instead a warning is raised and
106
-
&null; is returned.
107
-
</para>
108
107
</refsect1>
109
108

110
109
<refsect1 role="examples">
...
...
@@ -183,7 +182,6 @@ ba01
183
182
</para>
184
183
</refsect1>
185
184
</refentry>
186
-

187
185
<!-- Keep this comment at the end of the file
188
186
Local variables:
189
187
mode: sgml
190
188