xref: /PHP-8.2/ext/standard/tests/strings/url_t.phpt (revision 4a89e726)
1--TEST--
2parse_url() function
3--FILE--
4<?php
5$sample_urls = array (
6'',
7'64.246.30.37',
8'http://64.246.30.37',
9'http://64.246.30.37/',
10'64.246.30.37/',
11'64.246.30.37:80/',
12'php.net',
13'php.net/',
14'http://php.net',
15'http://php.net/',
16'www.php.net',
17'www.php.net/',
18'http://www.php.net',
19'http://www.php.net/',
20'www.php.net:80',
21'http://www.php.net:80',
22'http://www.php.net:80/',
23'http://www.php.net/index.php',
24'www.php.net/?',
25'www.php.net:80/?',
26'http://www.php.net/?',
27'http://www.php.net:80/?',
28'http://www.php.net:80/index.php',
29'http://www.php.net:80/foo/bar/index.php',
30'http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php',
31'http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php?lots=1&of=2&parameters=3&too=4&here=5',
32'http://www.php.net:80/this/is/a/very/deep/directory/structure/and/',
33'http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php',
34'http://www.php.net:80/this/../a/../deep/directory',
35'http://www.php.net:80/this/../a/../deep/directory/',
36'http://www.php.net:80/this/is/a/very/deep/directory/../file.php',
37'http://www.php.net:80/index.php',
38'http://www.php.net:80/index.php?',
39'http://www.php.net:80/#foo',
40'http://www.php.net:80/?#',
41'http://www.php.net:80/?test=1',
42'http://www.php.net/?test=1&',
43'http://www.php.net:80/?&',
44'http://www.php.net:80/index.php?test=1&',
45'http://www.php.net/index.php?&',
46'http://www.php.net:80/index.php?foo&',
47'http://www.php.net/index.php?&foo',
48'http://www.php.net:80/index.php?test=1&test2=char&test3=mixesCI',
49'www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123',
50'http://secret@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123',
51'http://secret:@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123',
52'http://:hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123',
53'http://secret:hideout@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123',
54'http://secret@hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123',
55'http://secret:hid:out@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123',
56'nntp://news.php.net',
57'ftp://ftp.gnu.org/gnu/glic/glibc.tar.gz',
58'zlib:http://foo@bar',
59'zlib:filename.txt',
60'zlib:/path/to/my/file/file.txt',
61'foo://foo@bar',
62'mailto:me@mydomain.com',
63'/foo.php?a=b&c=d',
64'foo.php?a=b&c=d',
65'http://user:passwd@www.example.com:8080?bar=1&boom=0',
66'file:///path/to/file',
67'file://path/to/file',
68'file:/path/to/file',
69'http://1.2.3.4:/abc.asp?a=1&b=2',
70'http://foo.com#bar',
71'scheme:',
72'foo+bar://baz@bang/bla',
73'gg:9130731',
74'http://user:@pass@host/path?argument?value#etc',
75);
76
77    foreach ($sample_urls as $url) {
78        echo "\n--> $url: ";
79        var_dump(@parse_url($url));
80    }
81
82    $url = 'http://secret:hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123';
83    foreach (array(PHP_URL_SCHEME,PHP_URL_HOST,PHP_URL_PORT,PHP_URL_USER,PHP_URL_PASS,PHP_URL_PATH,PHP_URL_QUERY,PHP_URL_FRAGMENT) as $v) {
84    var_dump(parse_url($url, $v));
85    }
86?>
87--EXPECT--
88--> : array(1) {
89  ["path"]=>
90  string(0) ""
91}
92
93--> 64.246.30.37: array(1) {
94  ["path"]=>
95  string(12) "64.246.30.37"
96}
97
98--> http://64.246.30.37: array(2) {
99  ["scheme"]=>
100  string(4) "http"
101  ["host"]=>
102  string(12) "64.246.30.37"
103}
104
105--> http://64.246.30.37/: array(3) {
106  ["scheme"]=>
107  string(4) "http"
108  ["host"]=>
109  string(12) "64.246.30.37"
110  ["path"]=>
111  string(1) "/"
112}
113
114--> 64.246.30.37/: array(1) {
115  ["path"]=>
116  string(13) "64.246.30.37/"
117}
118
119--> 64.246.30.37:80/: array(3) {
120  ["host"]=>
121  string(12) "64.246.30.37"
122  ["port"]=>
123  int(80)
124  ["path"]=>
125  string(1) "/"
126}
127
128--> php.net: array(1) {
129  ["path"]=>
130  string(7) "php.net"
131}
132
133--> php.net/: array(1) {
134  ["path"]=>
135  string(8) "php.net/"
136}
137
138--> http://php.net: array(2) {
139  ["scheme"]=>
140  string(4) "http"
141  ["host"]=>
142  string(7) "php.net"
143}
144
145--> http://php.net/: array(3) {
146  ["scheme"]=>
147  string(4) "http"
148  ["host"]=>
149  string(7) "php.net"
150  ["path"]=>
151  string(1) "/"
152}
153
154--> www.php.net: array(1) {
155  ["path"]=>
156  string(11) "www.php.net"
157}
158
159--> www.php.net/: array(1) {
160  ["path"]=>
161  string(12) "www.php.net/"
162}
163
164--> http://www.php.net: array(2) {
165  ["scheme"]=>
166  string(4) "http"
167  ["host"]=>
168  string(11) "www.php.net"
169}
170
171--> http://www.php.net/: array(3) {
172  ["scheme"]=>
173  string(4) "http"
174  ["host"]=>
175  string(11) "www.php.net"
176  ["path"]=>
177  string(1) "/"
178}
179
180--> www.php.net:80: array(2) {
181  ["host"]=>
182  string(11) "www.php.net"
183  ["port"]=>
184  int(80)
185}
186
187--> http://www.php.net:80: array(3) {
188  ["scheme"]=>
189  string(4) "http"
190  ["host"]=>
191  string(11) "www.php.net"
192  ["port"]=>
193  int(80)
194}
195
196--> http://www.php.net:80/: array(4) {
197  ["scheme"]=>
198  string(4) "http"
199  ["host"]=>
200  string(11) "www.php.net"
201  ["port"]=>
202  int(80)
203  ["path"]=>
204  string(1) "/"
205}
206
207--> http://www.php.net/index.php: array(3) {
208  ["scheme"]=>
209  string(4) "http"
210  ["host"]=>
211  string(11) "www.php.net"
212  ["path"]=>
213  string(10) "/index.php"
214}
215
216--> www.php.net/?: array(2) {
217  ["path"]=>
218  string(12) "www.php.net/"
219  ["query"]=>
220  string(0) ""
221}
222
223--> www.php.net:80/?: array(4) {
224  ["host"]=>
225  string(11) "www.php.net"
226  ["port"]=>
227  int(80)
228  ["path"]=>
229  string(1) "/"
230  ["query"]=>
231  string(0) ""
232}
233
234--> http://www.php.net/?: array(4) {
235  ["scheme"]=>
236  string(4) "http"
237  ["host"]=>
238  string(11) "www.php.net"
239  ["path"]=>
240  string(1) "/"
241  ["query"]=>
242  string(0) ""
243}
244
245--> http://www.php.net:80/?: array(5) {
246  ["scheme"]=>
247  string(4) "http"
248  ["host"]=>
249  string(11) "www.php.net"
250  ["port"]=>
251  int(80)
252  ["path"]=>
253  string(1) "/"
254  ["query"]=>
255  string(0) ""
256}
257
258--> http://www.php.net:80/index.php: array(4) {
259  ["scheme"]=>
260  string(4) "http"
261  ["host"]=>
262  string(11) "www.php.net"
263  ["port"]=>
264  int(80)
265  ["path"]=>
266  string(10) "/index.php"
267}
268
269--> http://www.php.net:80/foo/bar/index.php: array(4) {
270  ["scheme"]=>
271  string(4) "http"
272  ["host"]=>
273  string(11) "www.php.net"
274  ["port"]=>
275  int(80)
276  ["path"]=>
277  string(18) "/foo/bar/index.php"
278}
279
280--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php: array(4) {
281  ["scheme"]=>
282  string(4) "http"
283  ["host"]=>
284  string(11) "www.php.net"
285  ["port"]=>
286  int(80)
287  ["path"]=>
288  string(53) "/this/is/a/very/deep/directory/structure/and/file.php"
289}
290
291--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php?lots=1&of=2&parameters=3&too=4&here=5: array(5) {
292  ["scheme"]=>
293  string(4) "http"
294  ["host"]=>
295  string(11) "www.php.net"
296  ["port"]=>
297  int(80)
298  ["path"]=>
299  string(53) "/this/is/a/very/deep/directory/structure/and/file.php"
300  ["query"]=>
301  string(37) "lots=1&of=2&parameters=3&too=4&here=5"
302}
303
304--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/: array(4) {
305  ["scheme"]=>
306  string(4) "http"
307  ["host"]=>
308  string(11) "www.php.net"
309  ["port"]=>
310  int(80)
311  ["path"]=>
312  string(45) "/this/is/a/very/deep/directory/structure/and/"
313}
314
315--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php: array(4) {
316  ["scheme"]=>
317  string(4) "http"
318  ["host"]=>
319  string(11) "www.php.net"
320  ["port"]=>
321  int(80)
322  ["path"]=>
323  string(53) "/this/is/a/very/deep/directory/structure/and/file.php"
324}
325
326--> http://www.php.net:80/this/../a/../deep/directory: array(4) {
327  ["scheme"]=>
328  string(4) "http"
329  ["host"]=>
330  string(11) "www.php.net"
331  ["port"]=>
332  int(80)
333  ["path"]=>
334  string(28) "/this/../a/../deep/directory"
335}
336
337--> http://www.php.net:80/this/../a/../deep/directory/: array(4) {
338  ["scheme"]=>
339  string(4) "http"
340  ["host"]=>
341  string(11) "www.php.net"
342  ["port"]=>
343  int(80)
344  ["path"]=>
345  string(29) "/this/../a/../deep/directory/"
346}
347
348--> http://www.php.net:80/this/is/a/very/deep/directory/../file.php: array(4) {
349  ["scheme"]=>
350  string(4) "http"
351  ["host"]=>
352  string(11) "www.php.net"
353  ["port"]=>
354  int(80)
355  ["path"]=>
356  string(42) "/this/is/a/very/deep/directory/../file.php"
357}
358
359--> http://www.php.net:80/index.php: array(4) {
360  ["scheme"]=>
361  string(4) "http"
362  ["host"]=>
363  string(11) "www.php.net"
364  ["port"]=>
365  int(80)
366  ["path"]=>
367  string(10) "/index.php"
368}
369
370--> http://www.php.net:80/index.php?: array(5) {
371  ["scheme"]=>
372  string(4) "http"
373  ["host"]=>
374  string(11) "www.php.net"
375  ["port"]=>
376  int(80)
377  ["path"]=>
378  string(10) "/index.php"
379  ["query"]=>
380  string(0) ""
381}
382
383--> http://www.php.net:80/#foo: array(5) {
384  ["scheme"]=>
385  string(4) "http"
386  ["host"]=>
387  string(11) "www.php.net"
388  ["port"]=>
389  int(80)
390  ["path"]=>
391  string(1) "/"
392  ["fragment"]=>
393  string(3) "foo"
394}
395
396--> http://www.php.net:80/?#: array(6) {
397  ["scheme"]=>
398  string(4) "http"
399  ["host"]=>
400  string(11) "www.php.net"
401  ["port"]=>
402  int(80)
403  ["path"]=>
404  string(1) "/"
405  ["query"]=>
406  string(0) ""
407  ["fragment"]=>
408  string(0) ""
409}
410
411--> http://www.php.net:80/?test=1: array(5) {
412  ["scheme"]=>
413  string(4) "http"
414  ["host"]=>
415  string(11) "www.php.net"
416  ["port"]=>
417  int(80)
418  ["path"]=>
419  string(1) "/"
420  ["query"]=>
421  string(6) "test=1"
422}
423
424--> http://www.php.net/?test=1&: array(4) {
425  ["scheme"]=>
426  string(4) "http"
427  ["host"]=>
428  string(11) "www.php.net"
429  ["path"]=>
430  string(1) "/"
431  ["query"]=>
432  string(7) "test=1&"
433}
434
435--> http://www.php.net:80/?&: array(5) {
436  ["scheme"]=>
437  string(4) "http"
438  ["host"]=>
439  string(11) "www.php.net"
440  ["port"]=>
441  int(80)
442  ["path"]=>
443  string(1) "/"
444  ["query"]=>
445  string(1) "&"
446}
447
448--> http://www.php.net:80/index.php?test=1&: array(5) {
449  ["scheme"]=>
450  string(4) "http"
451  ["host"]=>
452  string(11) "www.php.net"
453  ["port"]=>
454  int(80)
455  ["path"]=>
456  string(10) "/index.php"
457  ["query"]=>
458  string(7) "test=1&"
459}
460
461--> http://www.php.net/index.php?&: array(4) {
462  ["scheme"]=>
463  string(4) "http"
464  ["host"]=>
465  string(11) "www.php.net"
466  ["path"]=>
467  string(10) "/index.php"
468  ["query"]=>
469  string(1) "&"
470}
471
472--> http://www.php.net:80/index.php?foo&: array(5) {
473  ["scheme"]=>
474  string(4) "http"
475  ["host"]=>
476  string(11) "www.php.net"
477  ["port"]=>
478  int(80)
479  ["path"]=>
480  string(10) "/index.php"
481  ["query"]=>
482  string(4) "foo&"
483}
484
485--> http://www.php.net/index.php?&foo: array(4) {
486  ["scheme"]=>
487  string(4) "http"
488  ["host"]=>
489  string(11) "www.php.net"
490  ["path"]=>
491  string(10) "/index.php"
492  ["query"]=>
493  string(4) "&foo"
494}
495
496--> http://www.php.net:80/index.php?test=1&test2=char&test3=mixesCI: array(5) {
497  ["scheme"]=>
498  string(4) "http"
499  ["host"]=>
500  string(11) "www.php.net"
501  ["port"]=>
502  int(80)
503  ["path"]=>
504  string(10) "/index.php"
505  ["query"]=>
506  string(31) "test=1&test2=char&test3=mixesCI"
507}
508
509--> www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(5) {
510  ["host"]=>
511  string(11) "www.php.net"
512  ["port"]=>
513  int(80)
514  ["path"]=>
515  string(10) "/index.php"
516  ["query"]=>
517  string(31) "test=1&test2=char&test3=mixesCI"
518  ["fragment"]=>
519  string(16) "some_page_ref123"
520}
521
522--> http://secret@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(7) {
523  ["scheme"]=>
524  string(4) "http"
525  ["host"]=>
526  string(11) "www.php.net"
527  ["port"]=>
528  int(80)
529  ["user"]=>
530  string(6) "secret"
531  ["path"]=>
532  string(10) "/index.php"
533  ["query"]=>
534  string(31) "test=1&test2=char&test3=mixesCI"
535  ["fragment"]=>
536  string(16) "some_page_ref123"
537}
538
539--> http://secret:@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(7) {
540  ["scheme"]=>
541  string(4) "http"
542  ["host"]=>
543  string(11) "www.php.net"
544  ["user"]=>
545  string(6) "secret"
546  ["pass"]=>
547  string(0) ""
548  ["path"]=>
549  string(10) "/index.php"
550  ["query"]=>
551  string(31) "test=1&test2=char&test3=mixesCI"
552  ["fragment"]=>
553  string(16) "some_page_ref123"
554}
555
556--> http://:hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(8) {
557  ["scheme"]=>
558  string(4) "http"
559  ["host"]=>
560  string(11) "www.php.net"
561  ["port"]=>
562  int(80)
563  ["user"]=>
564  string(0) ""
565  ["pass"]=>
566  string(7) "hideout"
567  ["path"]=>
568  string(10) "/index.php"
569  ["query"]=>
570  string(31) "test=1&test2=char&test3=mixesCI"
571  ["fragment"]=>
572  string(16) "some_page_ref123"
573}
574
575--> http://secret:hideout@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(7) {
576  ["scheme"]=>
577  string(4) "http"
578  ["host"]=>
579  string(11) "www.php.net"
580  ["user"]=>
581  string(6) "secret"
582  ["pass"]=>
583  string(7) "hideout"
584  ["path"]=>
585  string(10) "/index.php"
586  ["query"]=>
587  string(31) "test=1&test2=char&test3=mixesCI"
588  ["fragment"]=>
589  string(16) "some_page_ref123"
590}
591
592--> http://secret@hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(7) {
593  ["scheme"]=>
594  string(4) "http"
595  ["host"]=>
596  string(11) "www.php.net"
597  ["port"]=>
598  int(80)
599  ["user"]=>
600  string(14) "secret@hideout"
601  ["path"]=>
602  string(10) "/index.php"
603  ["query"]=>
604  string(31) "test=1&test2=char&test3=mixesCI"
605  ["fragment"]=>
606  string(16) "some_page_ref123"
607}
608
609--> http://secret:hid:out@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(8) {
610  ["scheme"]=>
611  string(4) "http"
612  ["host"]=>
613  string(11) "www.php.net"
614  ["port"]=>
615  int(80)
616  ["user"]=>
617  string(6) "secret"
618  ["pass"]=>
619  string(7) "hid:out"
620  ["path"]=>
621  string(10) "/index.php"
622  ["query"]=>
623  string(31) "test=1&test2=char&test3=mixesCI"
624  ["fragment"]=>
625  string(16) "some_page_ref123"
626}
627
628--> nntp://news.php.net: array(2) {
629  ["scheme"]=>
630  string(4) "nntp"
631  ["host"]=>
632  string(12) "news.php.net"
633}
634
635--> ftp://ftp.gnu.org/gnu/glic/glibc.tar.gz: array(3) {
636  ["scheme"]=>
637  string(3) "ftp"
638  ["host"]=>
639  string(11) "ftp.gnu.org"
640  ["path"]=>
641  string(22) "/gnu/glic/glibc.tar.gz"
642}
643
644--> zlib:http://foo@bar: array(2) {
645  ["scheme"]=>
646  string(4) "zlib"
647  ["path"]=>
648  string(14) "http://foo@bar"
649}
650
651--> zlib:filename.txt: array(2) {
652  ["scheme"]=>
653  string(4) "zlib"
654  ["path"]=>
655  string(12) "filename.txt"
656}
657
658--> zlib:/path/to/my/file/file.txt: array(2) {
659  ["scheme"]=>
660  string(4) "zlib"
661  ["path"]=>
662  string(25) "/path/to/my/file/file.txt"
663}
664
665--> foo://foo@bar: array(3) {
666  ["scheme"]=>
667  string(3) "foo"
668  ["host"]=>
669  string(3) "bar"
670  ["user"]=>
671  string(3) "foo"
672}
673
674--> mailto:me@mydomain.com: array(2) {
675  ["scheme"]=>
676  string(6) "mailto"
677  ["path"]=>
678  string(15) "me@mydomain.com"
679}
680
681--> /foo.php?a=b&c=d: array(2) {
682  ["path"]=>
683  string(8) "/foo.php"
684  ["query"]=>
685  string(7) "a=b&c=d"
686}
687
688--> foo.php?a=b&c=d: array(2) {
689  ["path"]=>
690  string(7) "foo.php"
691  ["query"]=>
692  string(7) "a=b&c=d"
693}
694
695--> http://user:passwd@www.example.com:8080?bar=1&boom=0: array(6) {
696  ["scheme"]=>
697  string(4) "http"
698  ["host"]=>
699  string(15) "www.example.com"
700  ["port"]=>
701  int(8080)
702  ["user"]=>
703  string(4) "user"
704  ["pass"]=>
705  string(6) "passwd"
706  ["query"]=>
707  string(12) "bar=1&boom=0"
708}
709
710--> file:///path/to/file: array(2) {
711  ["scheme"]=>
712  string(4) "file"
713  ["path"]=>
714  string(13) "/path/to/file"
715}
716
717--> file://path/to/file: array(3) {
718  ["scheme"]=>
719  string(4) "file"
720  ["host"]=>
721  string(4) "path"
722  ["path"]=>
723  string(8) "/to/file"
724}
725
726--> file:/path/to/file: array(2) {
727  ["scheme"]=>
728  string(4) "file"
729  ["path"]=>
730  string(13) "/path/to/file"
731}
732
733--> http://1.2.3.4:/abc.asp?a=1&b=2: array(4) {
734  ["scheme"]=>
735  string(4) "http"
736  ["host"]=>
737  string(7) "1.2.3.4"
738  ["path"]=>
739  string(8) "/abc.asp"
740  ["query"]=>
741  string(7) "a=1&b=2"
742}
743
744--> http://foo.com#bar: array(3) {
745  ["scheme"]=>
746  string(4) "http"
747  ["host"]=>
748  string(7) "foo.com"
749  ["fragment"]=>
750  string(3) "bar"
751}
752
753--> scheme:: array(1) {
754  ["scheme"]=>
755  string(6) "scheme"
756}
757
758--> foo+bar://baz@bang/bla: array(4) {
759  ["scheme"]=>
760  string(7) "foo+bar"
761  ["host"]=>
762  string(4) "bang"
763  ["user"]=>
764  string(3) "baz"
765  ["path"]=>
766  string(4) "/bla"
767}
768
769--> gg:9130731: array(2) {
770  ["scheme"]=>
771  string(2) "gg"
772  ["path"]=>
773  string(7) "9130731"
774}
775
776--> http://user:@pass@host/path?argument?value#etc: array(7) {
777  ["scheme"]=>
778  string(4) "http"
779  ["host"]=>
780  string(4) "host"
781  ["user"]=>
782  string(4) "user"
783  ["pass"]=>
784  string(5) "@pass"
785  ["path"]=>
786  string(5) "/path"
787  ["query"]=>
788  string(14) "argument?value"
789  ["fragment"]=>
790  string(3) "etc"
791}
792string(4) "http"
793string(11) "www.php.net"
794int(80)
795string(6) "secret"
796string(7) "hideout"
797string(10) "/index.php"
798string(31) "test=1&test2=char&test3=mixesCI"
799string(16) "some_page_ref123"
800