1--TEST-- 2Test parse_url() function: Parse a load of URLs without specifying PHP_URL_HOST as the URL component 3--FILE-- 4<?php 5/* Prototype : proto mixed parse_url(string url, [int url_component]) 6 * Description: Parse a URL and return its components 7 * Source code: ext/standard/url.c 8 * Alias to functions: 9 */ 10 11/* 12 * Parse a load of URLs without specifying PHP_URL_HOST as the URL component 13 */ 14include_once(dirname(__FILE__) . '/urls.inc'); 15 16foreach ($urls as $url) { 17 echo "--> $url : "; 18 var_dump(parse_url($url, PHP_URL_HOST)); 19} 20 21echo "Done"; 22?> 23--EXPECT-- 24--> 64.246.30.37 : NULL 25--> http://64.246.30.37 : string(12) "64.246.30.37" 26--> http://64.246.30.37/ : string(12) "64.246.30.37" 27--> 64.246.30.37/ : NULL 28--> 64.246.30.37:80/ : string(12) "64.246.30.37" 29--> php.net : NULL 30--> php.net/ : NULL 31--> http://php.net : string(7) "php.net" 32--> http://php.net/ : string(7) "php.net" 33--> www.php.net : NULL 34--> www.php.net/ : NULL 35--> http://www.php.net : string(11) "www.php.net" 36--> http://www.php.net/ : string(11) "www.php.net" 37--> www.php.net:80 : string(11) "www.php.net" 38--> http://www.php.net:80 : string(11) "www.php.net" 39--> http://www.php.net:80/ : string(11) "www.php.net" 40--> http://www.php.net/index.php : string(11) "www.php.net" 41--> www.php.net/? : NULL 42--> www.php.net:80/? : string(11) "www.php.net" 43--> http://www.php.net/? : string(11) "www.php.net" 44--> http://www.php.net:80/? : string(11) "www.php.net" 45--> http://www.php.net:80/index.php : string(11) "www.php.net" 46--> http://www.php.net:80/foo/bar/index.php : string(11) "www.php.net" 47--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php : string(11) "www.php.net" 48--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php?lots=1&of=2¶meters=3&too=4&here=5 : string(11) "www.php.net" 49--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/ : string(11) "www.php.net" 50--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php : string(11) "www.php.net" 51--> http://www.php.net:80/this/../a/../deep/directory : string(11) "www.php.net" 52--> http://www.php.net:80/this/../a/../deep/directory/ : string(11) "www.php.net" 53--> http://www.php.net:80/this/is/a/very/deep/directory/../file.php : string(11) "www.php.net" 54--> http://www.php.net:80/index.php : string(11) "www.php.net" 55--> http://www.php.net:80/index.php? : string(11) "www.php.net" 56--> http://www.php.net:80/#foo : string(11) "www.php.net" 57--> http://www.php.net:80/?# : string(11) "www.php.net" 58--> http://www.php.net:80/?test=1 : string(11) "www.php.net" 59--> http://www.php.net/?test=1& : string(11) "www.php.net" 60--> http://www.php.net:80/?& : string(11) "www.php.net" 61--> http://www.php.net:80/index.php?test=1& : string(11) "www.php.net" 62--> http://www.php.net/index.php?& : string(11) "www.php.net" 63--> http://www.php.net:80/index.php?foo& : string(11) "www.php.net" 64--> http://www.php.net/index.php?&foo : string(11) "www.php.net" 65--> http://www.php.net:80/index.php?test=1&test2=char&test3=mixesCI : string(11) "www.php.net" 66--> www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(11) "www.php.net" 67--> http://secret@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(11) "www.php.net" 68--> http://secret:@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(11) "www.php.net" 69--> http://:hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(11) "www.php.net" 70--> http://secret:hideout@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(11) "www.php.net" 71--> http://secret@hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(11) "www.php.net" 72--> http://secret:hid:out@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(11) "www.php.net" 73--> nntp://news.php.net : string(12) "news.php.net" 74--> ftp://ftp.gnu.org/gnu/glic/glibc.tar.gz : string(11) "ftp.gnu.org" 75--> zlib:http://foo@bar : NULL 76--> zlib:filename.txt : NULL 77--> zlib:/path/to/my/file/file.txt : NULL 78--> foo://foo@bar : string(3) "bar" 79--> mailto:me@mydomain.com : NULL 80--> /foo.php?a=b&c=d : NULL 81--> foo.php?a=b&c=d : NULL 82--> http://user:passwd@www.example.com:8080?bar=1&boom=0 : string(15) "www.example.com" 83--> http://user_me-you:my_pas-word@www.example.com:8080?bar=1&boom=0 : string(15) "www.example.com" 84--> file:///path/to/file : NULL 85--> file://path/to/file : string(4) "path" 86--> file:/path/to/file : NULL 87--> http://1.2.3.4:/abc.asp?a=1&b=2 : string(7) "1.2.3.4" 88--> http://foo.com#bar : string(7) "foo.com" 89--> scheme: : NULL 90--> foo+bar://baz@bang/bla : string(4) "bang" 91--> gg:9130731 : NULL 92--> http://user:@pass@host/path?argument?value#etc : string(4) "host" 93--> http://10.10.10.10/:80 : string(11) "10.10.10.10" 94--> http://x:? : string(1) "x" 95--> x:blah.com : NULL 96--> x:/blah.com : NULL 97--> x://::abc/? : bool(false) 98--> http://::? : string(1) ":" 99--> http://::# : string(1) ":" 100--> x://::6.5 : string(1) ":" 101--> http://?:/ : bool(false) 102--> http://@?:/ : bool(false) 103--> file:///: : NULL 104--> file:///a:/ : NULL 105--> file:///ab:/ : NULL 106--> file:///a:/ : NULL 107--> file:///@:/ : NULL 108--> file:///:80/ : NULL 109--> [] : NULL 110--> http://[x:80]/ : string(6) "[x:80]" 111--> : NULL 112--> / : NULL 113--> /rest/Users?filter={"id":"123"} : NULL 114--> %:x : NULL 115--> https://example.com:0/ : string(11) "example.com" 116--> http:///blah.com : bool(false) 117--> http://:80 : bool(false) 118--> http://user@:80 : bool(false) 119--> http://user:pass@:80 : bool(false) 120--> http://: : bool(false) 121--> http://@/ : bool(false) 122--> http://@:/ : bool(false) 123--> http://:/ : bool(false) 124--> http://? : bool(false) 125--> http://# : bool(false) 126--> http://?: : bool(false) 127--> http://:? : bool(false) 128--> http://blah.com:123456 : bool(false) 129--> http://blah.com:abcdef : bool(false) 130Done 131