xref: /PHP-7.2/ext/standard/tests/strings/url_t.phpt (revision 2d3d7241)
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(1) {
217  ["path"]=>
218  string(12) "www.php.net/"
219}
220
221--> www.php.net:80/?: array(3) {
222  ["host"]=>
223  string(11) "www.php.net"
224  ["port"]=>
225  int(80)
226  ["path"]=>
227  string(1) "/"
228}
229
230--> http://www.php.net/?: array(3) {
231  ["scheme"]=>
232  string(4) "http"
233  ["host"]=>
234  string(11) "www.php.net"
235  ["path"]=>
236  string(1) "/"
237}
238
239--> http://www.php.net:80/?: array(4) {
240  ["scheme"]=>
241  string(4) "http"
242  ["host"]=>
243  string(11) "www.php.net"
244  ["port"]=>
245  int(80)
246  ["path"]=>
247  string(1) "/"
248}
249
250--> http://www.php.net:80/index.php: array(4) {
251  ["scheme"]=>
252  string(4) "http"
253  ["host"]=>
254  string(11) "www.php.net"
255  ["port"]=>
256  int(80)
257  ["path"]=>
258  string(10) "/index.php"
259}
260
261--> http://www.php.net:80/foo/bar/index.php: array(4) {
262  ["scheme"]=>
263  string(4) "http"
264  ["host"]=>
265  string(11) "www.php.net"
266  ["port"]=>
267  int(80)
268  ["path"]=>
269  string(18) "/foo/bar/index.php"
270}
271
272--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php: array(4) {
273  ["scheme"]=>
274  string(4) "http"
275  ["host"]=>
276  string(11) "www.php.net"
277  ["port"]=>
278  int(80)
279  ["path"]=>
280  string(53) "/this/is/a/very/deep/directory/structure/and/file.php"
281}
282
283--> 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) {
284  ["scheme"]=>
285  string(4) "http"
286  ["host"]=>
287  string(11) "www.php.net"
288  ["port"]=>
289  int(80)
290  ["path"]=>
291  string(53) "/this/is/a/very/deep/directory/structure/and/file.php"
292  ["query"]=>
293  string(37) "lots=1&of=2&parameters=3&too=4&here=5"
294}
295
296--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/: array(4) {
297  ["scheme"]=>
298  string(4) "http"
299  ["host"]=>
300  string(11) "www.php.net"
301  ["port"]=>
302  int(80)
303  ["path"]=>
304  string(45) "/this/is/a/very/deep/directory/structure/and/"
305}
306
307--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php: array(4) {
308  ["scheme"]=>
309  string(4) "http"
310  ["host"]=>
311  string(11) "www.php.net"
312  ["port"]=>
313  int(80)
314  ["path"]=>
315  string(53) "/this/is/a/very/deep/directory/structure/and/file.php"
316}
317
318--> http://www.php.net:80/this/../a/../deep/directory: array(4) {
319  ["scheme"]=>
320  string(4) "http"
321  ["host"]=>
322  string(11) "www.php.net"
323  ["port"]=>
324  int(80)
325  ["path"]=>
326  string(28) "/this/../a/../deep/directory"
327}
328
329--> http://www.php.net:80/this/../a/../deep/directory/: array(4) {
330  ["scheme"]=>
331  string(4) "http"
332  ["host"]=>
333  string(11) "www.php.net"
334  ["port"]=>
335  int(80)
336  ["path"]=>
337  string(29) "/this/../a/../deep/directory/"
338}
339
340--> http://www.php.net:80/this/is/a/very/deep/directory/../file.php: array(4) {
341  ["scheme"]=>
342  string(4) "http"
343  ["host"]=>
344  string(11) "www.php.net"
345  ["port"]=>
346  int(80)
347  ["path"]=>
348  string(42) "/this/is/a/very/deep/directory/../file.php"
349}
350
351--> http://www.php.net:80/index.php: array(4) {
352  ["scheme"]=>
353  string(4) "http"
354  ["host"]=>
355  string(11) "www.php.net"
356  ["port"]=>
357  int(80)
358  ["path"]=>
359  string(10) "/index.php"
360}
361
362--> http://www.php.net:80/index.php?: array(4) {
363  ["scheme"]=>
364  string(4) "http"
365  ["host"]=>
366  string(11) "www.php.net"
367  ["port"]=>
368  int(80)
369  ["path"]=>
370  string(10) "/index.php"
371}
372
373--> http://www.php.net:80/#foo: array(5) {
374  ["scheme"]=>
375  string(4) "http"
376  ["host"]=>
377  string(11) "www.php.net"
378  ["port"]=>
379  int(80)
380  ["path"]=>
381  string(1) "/"
382  ["fragment"]=>
383  string(3) "foo"
384}
385
386--> http://www.php.net:80/?#: array(4) {
387  ["scheme"]=>
388  string(4) "http"
389  ["host"]=>
390  string(11) "www.php.net"
391  ["port"]=>
392  int(80)
393  ["path"]=>
394  string(1) "/"
395}
396
397--> http://www.php.net:80/?test=1: array(5) {
398  ["scheme"]=>
399  string(4) "http"
400  ["host"]=>
401  string(11) "www.php.net"
402  ["port"]=>
403  int(80)
404  ["path"]=>
405  string(1) "/"
406  ["query"]=>
407  string(6) "test=1"
408}
409
410--> http://www.php.net/?test=1&: array(4) {
411  ["scheme"]=>
412  string(4) "http"
413  ["host"]=>
414  string(11) "www.php.net"
415  ["path"]=>
416  string(1) "/"
417  ["query"]=>
418  string(7) "test=1&"
419}
420
421--> http://www.php.net:80/?&: array(5) {
422  ["scheme"]=>
423  string(4) "http"
424  ["host"]=>
425  string(11) "www.php.net"
426  ["port"]=>
427  int(80)
428  ["path"]=>
429  string(1) "/"
430  ["query"]=>
431  string(1) "&"
432}
433
434--> http://www.php.net:80/index.php?test=1&: array(5) {
435  ["scheme"]=>
436  string(4) "http"
437  ["host"]=>
438  string(11) "www.php.net"
439  ["port"]=>
440  int(80)
441  ["path"]=>
442  string(10) "/index.php"
443  ["query"]=>
444  string(7) "test=1&"
445}
446
447--> http://www.php.net/index.php?&: array(4) {
448  ["scheme"]=>
449  string(4) "http"
450  ["host"]=>
451  string(11) "www.php.net"
452  ["path"]=>
453  string(10) "/index.php"
454  ["query"]=>
455  string(1) "&"
456}
457
458--> http://www.php.net:80/index.php?foo&: array(5) {
459  ["scheme"]=>
460  string(4) "http"
461  ["host"]=>
462  string(11) "www.php.net"
463  ["port"]=>
464  int(80)
465  ["path"]=>
466  string(10) "/index.php"
467  ["query"]=>
468  string(4) "foo&"
469}
470
471--> http://www.php.net/index.php?&foo: array(4) {
472  ["scheme"]=>
473  string(4) "http"
474  ["host"]=>
475  string(11) "www.php.net"
476  ["path"]=>
477  string(10) "/index.php"
478  ["query"]=>
479  string(4) "&foo"
480}
481
482--> http://www.php.net:80/index.php?test=1&test2=char&test3=mixesCI: array(5) {
483  ["scheme"]=>
484  string(4) "http"
485  ["host"]=>
486  string(11) "www.php.net"
487  ["port"]=>
488  int(80)
489  ["path"]=>
490  string(10) "/index.php"
491  ["query"]=>
492  string(31) "test=1&test2=char&test3=mixesCI"
493}
494
495--> www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(5) {
496  ["host"]=>
497  string(11) "www.php.net"
498  ["port"]=>
499  int(80)
500  ["path"]=>
501  string(10) "/index.php"
502  ["query"]=>
503  string(31) "test=1&test2=char&test3=mixesCI"
504  ["fragment"]=>
505  string(16) "some_page_ref123"
506}
507
508--> http://secret@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(7) {
509  ["scheme"]=>
510  string(4) "http"
511  ["host"]=>
512  string(11) "www.php.net"
513  ["port"]=>
514  int(80)
515  ["user"]=>
516  string(6) "secret"
517  ["path"]=>
518  string(10) "/index.php"
519  ["query"]=>
520  string(31) "test=1&test2=char&test3=mixesCI"
521  ["fragment"]=>
522  string(16) "some_page_ref123"
523}
524
525--> http://secret:@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(7) {
526  ["scheme"]=>
527  string(4) "http"
528  ["host"]=>
529  string(11) "www.php.net"
530  ["user"]=>
531  string(6) "secret"
532  ["pass"]=>
533  string(0) ""
534  ["path"]=>
535  string(10) "/index.php"
536  ["query"]=>
537  string(31) "test=1&test2=char&test3=mixesCI"
538  ["fragment"]=>
539  string(16) "some_page_ref123"
540}
541
542--> http://:hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(8) {
543  ["scheme"]=>
544  string(4) "http"
545  ["host"]=>
546  string(11) "www.php.net"
547  ["port"]=>
548  int(80)
549  ["user"]=>
550  string(0) ""
551  ["pass"]=>
552  string(7) "hideout"
553  ["path"]=>
554  string(10) "/index.php"
555  ["query"]=>
556  string(31) "test=1&test2=char&test3=mixesCI"
557  ["fragment"]=>
558  string(16) "some_page_ref123"
559}
560
561--> http://secret:hideout@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(7) {
562  ["scheme"]=>
563  string(4) "http"
564  ["host"]=>
565  string(11) "www.php.net"
566  ["user"]=>
567  string(6) "secret"
568  ["pass"]=>
569  string(7) "hideout"
570  ["path"]=>
571  string(10) "/index.php"
572  ["query"]=>
573  string(31) "test=1&test2=char&test3=mixesCI"
574  ["fragment"]=>
575  string(16) "some_page_ref123"
576}
577
578--> http://secret@hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(6) {
579  ["scheme"]=>
580  string(4) "http"
581  ["host"]=>
582  string(26) "secret@hideout@www.php.net"
583  ["port"]=>
584  int(80)
585  ["path"]=>
586  string(10) "/index.php"
587  ["query"]=>
588  string(31) "test=1&test2=char&test3=mixesCI"
589  ["fragment"]=>
590  string(16) "some_page_ref123"
591}
592
593--> http://secret:hid:out@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(8) {
594  ["scheme"]=>
595  string(4) "http"
596  ["host"]=>
597  string(11) "www.php.net"
598  ["port"]=>
599  int(80)
600  ["user"]=>
601  string(6) "secret"
602  ["pass"]=>
603  string(7) "hid:out"
604  ["path"]=>
605  string(10) "/index.php"
606  ["query"]=>
607  string(31) "test=1&test2=char&test3=mixesCI"
608  ["fragment"]=>
609  string(16) "some_page_ref123"
610}
611
612--> nntp://news.php.net: array(2) {
613  ["scheme"]=>
614  string(4) "nntp"
615  ["host"]=>
616  string(12) "news.php.net"
617}
618
619--> ftp://ftp.gnu.org/gnu/glic/glibc.tar.gz: array(3) {
620  ["scheme"]=>
621  string(3) "ftp"
622  ["host"]=>
623  string(11) "ftp.gnu.org"
624  ["path"]=>
625  string(22) "/gnu/glic/glibc.tar.gz"
626}
627
628--> zlib:http://foo@bar: array(2) {
629  ["scheme"]=>
630  string(4) "zlib"
631  ["path"]=>
632  string(14) "http://foo@bar"
633}
634
635--> zlib:filename.txt: array(2) {
636  ["scheme"]=>
637  string(4) "zlib"
638  ["path"]=>
639  string(12) "filename.txt"
640}
641
642--> zlib:/path/to/my/file/file.txt: array(2) {
643  ["scheme"]=>
644  string(4) "zlib"
645  ["path"]=>
646  string(25) "/path/to/my/file/file.txt"
647}
648
649--> foo://foo@bar: array(3) {
650  ["scheme"]=>
651  string(3) "foo"
652  ["host"]=>
653  string(3) "bar"
654  ["user"]=>
655  string(3) "foo"
656}
657
658--> mailto:me@mydomain.com: array(2) {
659  ["scheme"]=>
660  string(6) "mailto"
661  ["path"]=>
662  string(15) "me@mydomain.com"
663}
664
665--> /foo.php?a=b&c=d: array(2) {
666  ["path"]=>
667  string(8) "/foo.php"
668  ["query"]=>
669  string(7) "a=b&c=d"
670}
671
672--> foo.php?a=b&c=d: array(2) {
673  ["path"]=>
674  string(7) "foo.php"
675  ["query"]=>
676  string(7) "a=b&c=d"
677}
678
679--> http://user:passwd@www.example.com:8080?bar=1&boom=0: array(6) {
680  ["scheme"]=>
681  string(4) "http"
682  ["host"]=>
683  string(15) "www.example.com"
684  ["port"]=>
685  int(8080)
686  ["user"]=>
687  string(4) "user"
688  ["pass"]=>
689  string(6) "passwd"
690  ["query"]=>
691  string(12) "bar=1&boom=0"
692}
693
694--> file:///path/to/file: array(2) {
695  ["scheme"]=>
696  string(4) "file"
697  ["path"]=>
698  string(13) "/path/to/file"
699}
700
701--> file://path/to/file: array(3) {
702  ["scheme"]=>
703  string(4) "file"
704  ["host"]=>
705  string(4) "path"
706  ["path"]=>
707  string(8) "/to/file"
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--> http://1.2.3.4:/abc.asp?a=1&b=2: array(4) {
718  ["scheme"]=>
719  string(4) "http"
720  ["host"]=>
721  string(7) "1.2.3.4"
722  ["path"]=>
723  string(8) "/abc.asp"
724  ["query"]=>
725  string(7) "a=1&b=2"
726}
727
728--> http://foo.com#bar: array(3) {
729  ["scheme"]=>
730  string(4) "http"
731  ["host"]=>
732  string(7) "foo.com"
733  ["fragment"]=>
734  string(3) "bar"
735}
736
737--> scheme:: array(1) {
738  ["scheme"]=>
739  string(6) "scheme"
740}
741
742--> foo+bar://baz@bang/bla: array(4) {
743  ["scheme"]=>
744  string(7) "foo+bar"
745  ["host"]=>
746  string(4) "bang"
747  ["user"]=>
748  string(3) "baz"
749  ["path"]=>
750  string(4) "/bla"
751}
752
753--> gg:9130731: array(2) {
754  ["scheme"]=>
755  string(2) "gg"
756  ["path"]=>
757  string(7) "9130731"
758}
759
760--> http://user:@pass@host/path?argument?value#etc: array(7) {
761  ["scheme"]=>
762  string(4) "http"
763  ["host"]=>
764  string(4) "host"
765  ["user"]=>
766  string(4) "user"
767  ["pass"]=>
768  string(5) "@pass"
769  ["path"]=>
770  string(5) "/path"
771  ["query"]=>
772  string(14) "argument?value"
773  ["fragment"]=>
774  string(3) "etc"
775}
776string(4) "http"
777string(11) "www.php.net"
778int(80)
779string(6) "secret"
780string(7) "hideout"
781string(10) "/index.php"
782string(31) "test=1&test2=char&test3=mixesCI"
783string(16) "some_page_ref123"
784