reference/strings/functions/explode.xml
45042fef652f1b4e904e809fcbfcf31f6c60670b
...
...
@@ -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.explode">
3
+
<refentry xml:id="function.explode" xmlns="http://docbook.org/ns/docbook">
4
4
<refnamediv>
5
5
<refname>explode</refname>
6
6
<refpurpose>Split a string by a string</refpurpose>
...
...
@@ -10,14 +10,14 @@
10
10
&reftitle.description;
11
11
<methodsynopsis>
12
12
<type>array</type><methodname>explode</methodname>
13
-
<methodparam><type>string</type><parameter>delimiter</parameter></methodparam>
13
+
<methodparam><type>string</type><parameter>separator</parameter></methodparam>
14
14
<methodparam><type>string</type><parameter>string</parameter></methodparam>
15
-
<methodparam choice="opt"><type>int</type><parameter>limit</parameter><initializer>PHP_INT_MAX</initializer></methodparam>
15
+
<methodparam choice="opt"><type>int</type><parameter>limit</parameter><initializer><constant>PHP_INT_MAX</constant></initializer></methodparam>
16
16
</methodsynopsis>
17
17
<para>
18
18
Returns an array of strings, each of which is a substring of
19
19
<parameter>string</parameter> formed by splitting it on
20
-
boundaries formed by the string <parameter>delimiter</parameter>.
20
+
boundaries formed by the string <parameter>separator</parameter>.
21
21
</para>
22
22
</refsect1>
23
23

...
...
@@ -26,7 +26,7 @@
26
26
<para>
27
27
<variablelist>
28
28
<varlistentry>
29
-
<term><parameter>delimiter</parameter></term>
29
+
<term><parameter>separator</parameter></term>
30
30
<listitem>
31
31
<para>
32
32
The boundary string.
...
...
@@ -62,10 +62,9 @@
62
62
</para>
63
63
<note>
64
64
<para>
65
-
Although <function>implode</function> can, for historical reasons,
66
-
accept its parameters in either order,
67
-
<function>explode</function> cannot. You must ensure that the
68
-
<parameter>delimiter</parameter> argument comes before the
65
+
Prior to PHP 8.0, <function>implode</function> accepted its parameters in either order.
66
+
<function>explode</function> has never supported this: you must ensure that the
67
+
<parameter>separator</parameter> argument comes before the
69
68
<parameter>string</parameter> argument.
70
69
</para>
71
70
</note>
...
...
@@ -76,41 +75,45 @@
76
75
<para>
77
76
Returns an <type>array</type> of <type>string</type>s
78
77
created by splitting the <parameter>string</parameter> parameter on
79
-
boundaries formed by the <parameter>delimiter</parameter>.
78
+
boundaries formed by the <parameter>separator</parameter>.
80
79
</para>
81
80
<para>
82
-
If <parameter>delimiter</parameter> is an empty <type>string</type> (""),
83
-
<function>explode</function> will return &false;.
84
-
If <parameter>delimiter</parameter> contains a value that is not
81
+
If <parameter>separator</parameter> is an empty <type>string</type> (""),
82
+
<function>explode</function> throws a <classname>ValueError</classname>.
83
+
If <parameter>separator</parameter> contains a value that is not
85
84
contained in <parameter>string</parameter> and a negative
86
85
<parameter>limit</parameter> is used, then an empty <type>array</type> will be
87
86
returned, otherwise an <type>array</type> containing
88
-
<parameter>string</parameter> will be returned.
87
+
<parameter>string</parameter> will be returned. If <parameter>separator</parameter>
88
+
values appear at the start or end of <parameter>string</parameter>, said values
89
+
will be added as an empty <type>array</type> value either in the first or last
90
+
position of the returned <type>array</type> respectively.
89
91
</para>
90
92
</refsect1>
91
93

92
94
<refsect1 role="changelog">
93
95
&reftitle.changelog;
94
-
<para>
95
-
<informaltable>
96
-
<tgroup cols="2">
97
-
<thead>
98
-
<row>
99
-
<entry>&Version;</entry>
100
-
<entry>&Description;</entry>
101
-
</row>
102
-
</thead>
103
-
<tbody>
104
-
<row>
105
-
<entry>5.1.0</entry>
106
-
<entry>
107
-
Support for negative <parameter>limit</parameter>s was added
108
-
</entry>
109
-
</row>
110
-
</tbody>
111
-
</tgroup>
112
-
</informaltable>
113
-
</para>
96
+
<informaltable>
97
+
<tgroup cols="2">
98
+
<thead>
99
+
<row>
100
+
<entry>&Version;</entry>
101
+
<entry>&Description;</entry>
102
+
</row>
103
+
</thead>
104
+
<tbody>
105
+
<row>
106
+
<entry>8.0.0</entry>
107
+
<entry>
108
+
<function>explode</function> will now throw <classname>ValueError</classname>
109
+
when <parameter>separator</parameter> parameter is given an empty string
110
+
(<literal>""</literal>).
111
+
Previously, <function>explode</function> returned &false; instead.
112
+
</entry>
113
+
</row>
114
+
</tbody>
115
+
</tgroup>
116
+
</informaltable>
114
117
</refsect1>
115
118

116
119
<refsect1 role="examples">
...
...
@@ -124,15 +127,14 @@
124
127
// Example 1
125
128
$pizza = "piece1 piece2 piece3 piece4 piece5 piece6";
126
129
$pieces = explode(" ", $pizza);
127
-
echo $pieces[0]; // piece1
128
-
echo $pieces[1]; // piece2
130
+
echo $pieces[0], PHP_EOL; // piece1
131
+
echo $pieces[1], PHP_EOL; // piece2
129
132

130
133
// Example 2
131
134
$data = "foo:*:1023:1000::/home/foo:/bin/sh";
132
135
list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data);
133
-
echo $user; // foo
134
-
echo $pass; // *
135
-

136
+
echo $user, PHP_EOL; // foo
137
+
echo $pass, PHP_EOL; // *
136
138
?>
137
139
]]>
138
140
</programlisting>
...
...
@@ -190,7 +192,7 @@ $str = 'one|two|three|four';
190
192
// positive limit
191
193
print_r(explode('|', $str, 2));
192
194

193
-
// negative limit (since PHP 5.1)
195
+
// negative limit
194
196
print_r(explode('|', $str, -1));
195
197
?>
196
198
]]>
...
...
@@ -235,7 +237,6 @@ Array
235
237
</refsect1>
236
238

237
239
</refentry>
238
-

239
240
<!-- Keep this comment at the end of the file
240
241
Local variables:
241
242
mode: sgml
242
243