reference/url/functions/parse-url.xml
195fde0082f2771a210a2818d3d4fa09c7ee785d
...
...
@@ -9,17 +9,18 @@
9
9
<refsect1 role="description">
10
10
&reftitle.description;
11
11
<methodsynopsis>
12
-
<type>mixed</type><methodname>parse_url</methodname>
12
+
<type class="union"><type>int</type><type>string</type><type>array</type><type>null</type><type>false</type></type><methodname>parse_url</methodname>
13
13
<methodparam><type>string</type><parameter>url</parameter></methodparam>
14
14
<methodparam choice="opt"><type>int</type><parameter>component</parameter><initializer>-1</initializer></methodparam>
15
15
</methodsynopsis>
16
16
<para>
17
17
This function parses a URL and returns an associative array containing any
18
18
of the various components of the URL that are present.
19
+
The values of the array elements are <emphasis>not</emphasis> URL decoded.
19
20
</para>
20
21
<para>
21
22
This function is <emphasis role="strong">not</emphasis> meant to validate
22
-
the given URL, it only breaks it up into the above listed parts. Partial
23
+
the given URL, it only breaks it up into the parts listed below. Partial and invalid
23
24
URLs are also accepted, <function>parse_url</function> tries its best to
24
25
parse them correctly.
25
26
</para>
...
...
@@ -33,8 +34,7 @@
33
34
<term><parameter>url</parameter></term>
34
35
<listitem>
35
36
<para>
36
-
The URL to parse. Invalid characters are replaced by
37
-
<literal>_</literal>.
37
+
The URL to parse.
38
38
</para>
39
39
</listitem>
40
40
</varlistentry>
...
...
@@ -51,7 +51,7 @@
51
51
or <constant>PHP_URL_FRAGMENT</constant> to retrieve just a specific
52
52
URL component as a <type>string</type> (except when
53
53
<constant>PHP_URL_PORT</constant> is given, in which case the return
54
-
value will be an <type>integer</type>).
54
+
value will be an <type>int</type>).
55
55
</para>
56
56
</listitem>
57
57
</varlistentry>
...
...
@@ -115,46 +115,54 @@
115
115
<para>
116
116
If the <parameter>component</parameter> parameter is specified,
117
117
<function>parse_url</function> returns a <type>string</type> (or an
118
-
<type>integer</type>, in the case of <constant>PHP_URL_PORT</constant>)
118
+
<type>int</type>, in the case of <constant>PHP_URL_PORT</constant>)
119
119
instead of an <type>array</type>. If the requested component doesn't exist
120
120
within the given URL, &null; will be returned.
121
+
As of PHP 8.0.0, <function>parse_url</function> distinguishes absent and empty
122
+
queries and fragments:
123
+
</para>
124
+
<para>
125
+
<informalexample>
126
+
<screen>
127
+
<![CDATA[
128
+
http://example.com/foo → query = null, fragment = null
129
+
http://example.com/foo? → query = "", fragment = null
130
+
http://example.com/foo# → query = null, fragment = ""
131
+
http://example.com/foo?# → query = "", fragment = ""
132
+
]]>
133
+
</screen>
134
+
</informalexample>
135
+
</para>
136
+
<para>
137
+
Previously all cases resulted in query and fragment being &null;.
138
+
</para>
139
+
<para>
140
+
Note that control characters (cf. <function>ctype_cntrl</function>) in the
141
+
components are replaced with underscores (<literal>_</literal>).
121
142
</para>
122
143
</refsect1>
123
144

124
145
<refsect1 role="changelog">
125
146
&reftitle.changelog;
126
-
<para>
127
-
<informaltable>
128
-
<tgroup cols="2">
129
-
<thead>
130
-
<row>
131
-
<entry>&Version;</entry>
132
-
<entry>&Description;</entry>
133
-
</row>
134
-
</thead>
135
-
<tbody>
136
-
<row>
137
-
<entry>5.4.7</entry>
138
-
<entry>
139
-
Fixed <emphasis>host</emphasis> recognition when <emphasis>scheme</emphasis>
140
-
is omitted and a leading component separator is present.
141
-
</entry>
142
-
</row>
143
-
<row>
144
-
<entry>5.3.3</entry>
145
-
<entry>
146
-
Removed the <constant>E_WARNING</constant> that was emitted when URL
147
-
parsing failed.
148
-
</entry>
149
-
</row>
150
-
<row>
151
-
<entry>5.1.2</entry>
152
-
<entry>Added the <parameter>component</parameter> parameter.</entry>
153
-
</row>
154
-
</tbody>
155
-
</tgroup>
156
-
</informaltable>
157
-
</para>
147
+
<informaltable>
148
+
<tgroup cols="2">
149
+
<thead>
150
+
<row>
151
+
<entry>&Version;</entry>
152
+
<entry>&Description;</entry>
153
+
</row>
154
+
</thead>
155
+
<tbody>
156
+
<row>
157
+
<entry>8.0.0</entry>
158
+
<entry>
159
+
<function>parse_url</function> will now distinguish absent and empty queries
160
+
and fragments.
161
+
</entry>
162
+
</row>
163
+
</tbody>
164
+
</tgroup>
165
+
</informaltable>
158
166
</refsect1>
159
167

160
168
<refsect1 role="examples">
...
...
@@ -244,11 +252,15 @@ array(3) {
244
252

245
253
<refsect1 role="notes">
246
254
&reftitle.notes;
247
-
<note>
255
+
<caution>
248
256
<para>
249
-
This function doesn't work with relative URLs.
257
+
This function may not give correct results for relative or invalid URLs,
258
+
and the results may not even match common behavior of HTTP clients.
259
+
If URLs from untrusted input need to be parsed, extra validation is
260
+
required, e.g. by using <function>filter_var</function> with the
261
+
<constant>FILTER_VALIDATE_URL</constant> filter.
250
262
</para>
251
-
</note>
263
+
</caution>
252
264
<note>
253
265
<para>
254
266
This function is intended specifically for the purpose of parsing URLs
...
...
@@ -273,7 +285,6 @@ array(3) {
273
285
</para>
274
286
</refsect1>
275
287
</refentry>
276
-

277
288
<!-- Keep this comment at the end of the file
278
289
Local variables:
279
290
mode: sgml
280
291