xref: /PHP-5.6/ext/standard/tests/strings/url_t.phpt (revision bc3a0b82)
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(7) {
579  ["scheme"]=>
580  string(4) "http"
581  ["host"]=>
582  string(11) "www.php.net"
583  ["port"]=>
584  int(80)
585  ["user"]=>
586  string(14) "secret@hideout"
587  ["path"]=>
588  string(10) "/index.php"
589  ["query"]=>
590  string(31) "test=1&test2=char&test3=mixesCI"
591  ["fragment"]=>
592  string(16) "some_page_ref123"
593}
594
595--> http://secret:hid:out@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(8) {
596  ["scheme"]=>
597  string(4) "http"
598  ["host"]=>
599  string(11) "www.php.net"
600  ["port"]=>
601  int(80)
602  ["user"]=>
603  string(6) "secret"
604  ["pass"]=>
605  string(7) "hid:out"
606  ["path"]=>
607  string(10) "/index.php"
608  ["query"]=>
609  string(31) "test=1&test2=char&test3=mixesCI"
610  ["fragment"]=>
611  string(16) "some_page_ref123"
612}
613
614--> nntp://news.php.net: array(2) {
615  ["scheme"]=>
616  string(4) "nntp"
617  ["host"]=>
618  string(12) "news.php.net"
619}
620
621--> ftp://ftp.gnu.org/gnu/glic/glibc.tar.gz: array(3) {
622  ["scheme"]=>
623  string(3) "ftp"
624  ["host"]=>
625  string(11) "ftp.gnu.org"
626  ["path"]=>
627  string(22) "/gnu/glic/glibc.tar.gz"
628}
629
630--> zlib:http://foo@bar: array(2) {
631  ["scheme"]=>
632  string(4) "zlib"
633  ["path"]=>
634  string(14) "http://foo@bar"
635}
636
637--> zlib:filename.txt: array(2) {
638  ["scheme"]=>
639  string(4) "zlib"
640  ["path"]=>
641  string(12) "filename.txt"
642}
643
644--> zlib:/path/to/my/file/file.txt: array(2) {
645  ["scheme"]=>
646  string(4) "zlib"
647  ["path"]=>
648  string(25) "/path/to/my/file/file.txt"
649}
650
651--> foo://foo@bar: array(3) {
652  ["scheme"]=>
653  string(3) "foo"
654  ["host"]=>
655  string(3) "bar"
656  ["user"]=>
657  string(3) "foo"
658}
659
660--> mailto:me@mydomain.com: array(2) {
661  ["scheme"]=>
662  string(6) "mailto"
663  ["path"]=>
664  string(15) "me@mydomain.com"
665}
666
667--> /foo.php?a=b&c=d: array(2) {
668  ["path"]=>
669  string(8) "/foo.php"
670  ["query"]=>
671  string(7) "a=b&c=d"
672}
673
674--> foo.php?a=b&c=d: array(2) {
675  ["path"]=>
676  string(7) "foo.php"
677  ["query"]=>
678  string(7) "a=b&c=d"
679}
680
681--> http://user:passwd@www.example.com:8080?bar=1&boom=0: array(6) {
682  ["scheme"]=>
683  string(4) "http"
684  ["host"]=>
685  string(15) "www.example.com"
686  ["port"]=>
687  int(8080)
688  ["user"]=>
689  string(4) "user"
690  ["pass"]=>
691  string(6) "passwd"
692  ["query"]=>
693  string(12) "bar=1&boom=0"
694}
695
696--> file:///path/to/file: array(2) {
697  ["scheme"]=>
698  string(4) "file"
699  ["path"]=>
700  string(13) "/path/to/file"
701}
702
703--> file://path/to/file: array(3) {
704  ["scheme"]=>
705  string(4) "file"
706  ["host"]=>
707  string(4) "path"
708  ["path"]=>
709  string(8) "/to/file"
710}
711
712--> file:/path/to/file: array(2) {
713  ["scheme"]=>
714  string(4) "file"
715  ["path"]=>
716  string(13) "/path/to/file"
717}
718
719--> http://1.2.3.4:/abc.asp?a=1&b=2: array(4) {
720  ["scheme"]=>
721  string(4) "http"
722  ["host"]=>
723  string(7) "1.2.3.4"
724  ["path"]=>
725  string(8) "/abc.asp"
726  ["query"]=>
727  string(7) "a=1&b=2"
728}
729
730--> http://foo.com#bar: array(3) {
731  ["scheme"]=>
732  string(4) "http"
733  ["host"]=>
734  string(7) "foo.com"
735  ["fragment"]=>
736  string(3) "bar"
737}
738
739--> scheme:: array(1) {
740  ["scheme"]=>
741  string(6) "scheme"
742}
743
744--> foo+bar://baz@bang/bla: array(4) {
745  ["scheme"]=>
746  string(7) "foo+bar"
747  ["host"]=>
748  string(4) "bang"
749  ["user"]=>
750  string(3) "baz"
751  ["path"]=>
752  string(4) "/bla"
753}
754
755--> gg:9130731: array(2) {
756  ["scheme"]=>
757  string(2) "gg"
758  ["path"]=>
759  string(7) "9130731"
760}
761
762--> http://user:@pass@host/path?argument?value#etc: array(7) {
763  ["scheme"]=>
764  string(4) "http"
765  ["host"]=>
766  string(4) "host"
767  ["user"]=>
768  string(4) "user"
769  ["pass"]=>
770  string(5) "@pass"
771  ["path"]=>
772  string(5) "/path"
773  ["query"]=>
774  string(14) "argument?value"
775  ["fragment"]=>
776  string(3) "etc"
777}
778string(4) "http"
779string(11) "www.php.net"
780int(80)
781string(6) "secret"
782string(7) "hideout"
783string(10) "/index.php"
784string(31) "test=1&test2=char&test3=mixesCI"
785string(16) "some_page_ref123"
786
787