3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $regex_url = <<<REGEX ` (?(DEFINE) (?<slash_seg> /(?&pchar)* ) (?<pchar> [a-zA-Z\d\-._~!$&'()*+,;=:@%]* ) (?<queryfrag> [a-zA-Z\d\-._~!$&'()*+,;=:@%/?]* ) ) ^ (?: (?<scheme> [a-zA-Z][a-zA-Z\d+\-.]* ) :)? (?: (?: // (?: (?<userinfo> (?<user> [a-zA-Z\d\-._~!$&'()*+,;=%]*) (?: :(?<pass> [a-zA-Z\d\-._~!$&'()*+,;=%:]*) )? ) @)? (?<host> (?<host_name> [a-zA-Z\d\-\.%]+ ) | (?<ipv4> \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} ) | (?: \[ (?<ipv6> [a-fA-F\d.:]+ ) \] ) ) (?: :(?<port> \d*) )? ) (?<path> (?: /(?&pchar)* )* ) | (?<path_abs> /(?: (?&pchar)+ (?&slash_seg)* )? ) | (?<path_rel> (?&pchar)+ (?&slash_seg)* ) )? (?: \? (?<query> (?&queryfrag) ) )? (?: \# (?<fragment> (?&queryfrag) ) )? `x REGEX; $urls = [ 'scheme://username:password@domain:443/path?query_string#fragment_id', 'http://en.wikipedia.org/wiki/URI#Examples_of_URI_references', 'http://127.0.0.1/ipv4', 'http://[db8:0cec::99:123a]/ipv6', 'http://example.org/absolute/URI/with/absolute/path/to/resource.txt', '//example.org/scheme-relative/URI/with/absolute/path/to/resource.txt', '/relative/URI/with/absolute/path/to/resource.txt', 'relative/path/to/resource.txt', '../../../resource.txt', './resource.txt#frag01', 'resource.txt', '#frag01', '', ]; foreach($urls as $url) { preg_match($regex_url, $url, $m); var_dump($m); }
based on MWHin
Output for 5.4.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(35) { [0]=> string(67) "scheme://username:password@domain:443/path?query_string#fragment_id" ["slash_seg"]=> string(0) "" [1]=> string(0) "" ["pchar"]=> string(0) "" [2]=> string(0) "" ["queryfrag"]=> string(0) "" [3]=> string(0) "" ["scheme"]=> string(6) "scheme" [4]=> string(6) "scheme" ["userinfo"]=> string(17) "username:password" [5]=> string(17) "username:password" ["user"]=> string(8) "username" [6]=> string(8) "username" ["pass"]=> string(8) "password" [7]=> string(8) "password" ["host"]=> string(6) "domain" [8]=> string(6) "domain" ["host_name"]=> string(6) "domain" [9]=> string(6) "domain" ["ipv4"]=> string(0) "" [10]=> string(0) "" ["ipv6"]=> string(0) "" [11]=> string(0) "" ["port"]=> string(3) "443" [12]=> string(3) "443" ["path"]=> string(5) "/path" [13]=> string(5) "/path" ["path_abs"]=> string(0) "" [14]=> string(0) "" ["path_rel"]=> string(0) "" [15]=> string(0) "" ["query"]=> string(12) "query_string" [16]=> string(12) "query_string" ["fragment"]=> string(11) "fragment_id" [17]=> string(11) "fragment_id" } array(35) { [0]=> string(59) "http://en.wikipedia.org/wiki/URI#Examples_of_URI_references" ["slash_seg"]=> string(0) "" [1]=> string(0) "" ["pchar"]=> string(0) "" [2]=> string(0) "" ["queryfrag"]=> string(0) "" [3]=> string(0) "" ["scheme"]=> string(4) "http" [4]=> string(4) "http" ["userinfo"]=> string(0) "" [5]=> string(0) "" ["user"]=> string(0) "" [6]=> string(0) "" ["pass"]=> string(0) "" [7]=> string(0) "" ["host"]=> string(16) "en.wikipedia.org" [8]=> string(16) "en.wikipedia.org" ["host_name"]=> string(16) "en.wikipedia.org" [9]=> string(16) "en.wikipedia.org" ["ipv4"]=> string(0) "" [10]=> string(0) "" ["ipv6"]=> string(0) "" [11]=> string(0) "" ["port"]=> string(0) "" [12]=> string(0) "" ["path"]=> string(9) "/wiki/URI" [13]=> string(9) "/wiki/URI" ["path_abs"]=> string(0) "" [14]=> string(0) "" ["path_rel"]=> string(0) "" [15]=> string(0) "" ["query"]=> string(0) "" [16]=> string(0) "" ["fragment"]=> string(26) "Examples_of_URI_references" [17]=> string(26) "Examples_of_URI_references" } array(27) { [0]=> string(21) "http://127.0.0.1/ipv4" ["slash_seg"]=> string(0) "" [1]=> string(0) "" ["pchar"]=> string(0) "" [2]=> string(0) "" ["queryfrag"]=> string(0) "" [3]=> string(0) "" ["scheme"]=> string(4) "http" [4]=> string(4) "http" ["userinfo"]=> string(0) "" [5]=> string(0) "" ["user"]=> string(0) "" [6]=> string(0) "" ["pass"]=> string(0) "" [7]=> string(0) "" ["host"]=> string(9) "127.0.0.1" [8]=> string(9) "127.0.0.1" ["host_name"]=> string(9) "127.0.0.1" [9]=> string(9) "127.0.0.1" ["ipv4"]=> string(0) "" [10]=> string(0) "" ["ipv6"]=> string(0) "" [11]=> string(0) "" ["port"]=> string(0) "" [12]=> string(0) "" ["path"]=> string(5) "/ipv4" [13]=> string(5) "/ipv4" } array(27) { [0]=> string(31) "http://[db8:0cec::99:123a]/ipv6" ["slash_seg"]=> string(0) "" [1]=> string(0) "" ["pchar"]=> string(0) "" [2]=> string(0) "" ["queryfrag"]=> string(0) "" [3]=> string(0) "" ["scheme"]=> string(4) "http" [4]=> string(4) "http" ["userinfo"]=> string(0) "" [5]=> string(0) "" ["user"]=> string(0) "" [6]=> string(0) "" ["pass"]=> string(0) "" [7]=> string(0) "" ["host"]=> string(19) "[db8:0cec::99:123a]" [8]=> string(19) "[db8:0cec::99:123a]" ["host_name"]=> string(0) "" [9]=> string(0) "" ["ipv4"]=> string(0) "" [10]=> string(0) "" ["ipv6"]=> string(17) "db8:0cec::99:123a" [11]=> string(17) "db8:0cec::99:123a" ["port"]=> string(0) "" [12]=> string(0) "" ["path"]=> string(5) "/ipv6" [13]=> string(5) "/ipv6" } array(27) { [0]=> string(66) "http://example.org/absolute/URI/with/absolute/path/to/resource.txt" ["slash_seg"]=> string(0) "" [1]=> string(0) "" ["pchar"]=> string(0) "" [2]=> string(0) "" ["queryfrag"]=> string(0) "" [3]=> string(0) "" ["scheme"]=> string(4) "http" [4]=> string(4) "http" ["userinfo"]=> string(0) "" [5]=> string(0) "" ["user"]=> string(0) "" [6]=> string(0) "" ["pass"]=> string(0) "" [7]=> string(0) "" ["host"]=> string(11) "example.org" [8]=> string(11) "example.org" ["host_name"]=> string(11) "example.org" [9]=> string(11) "example.org" ["ipv4"]=> string(0) "" [10]=> string(0) "" ["ipv6"]=> string(0) "" [11]=> string(0) "" ["port"]=> string(0) "" [12]=> string(0) "" ["path"]=> string(48) "/absolute/URI/with/absolute/path/to/resource.txt" [13]=> string(48) "/absolute/URI/with/absolute/path/to/resource.txt" } array(27) { [0]=> string(68) "//example.org/scheme-relative/URI/with/absolute/path/to/resource.txt" ["slash_seg"]=> string(0) "" [1]=> string(0) "" ["pchar"]=> string(0) "" [2]=> string(0) "" ["queryfrag"]=> string(0) "" [3]=> string(0) "" ["scheme"]=> string(0) "" [4]=> string(0) "" ["userinfo"]=> string(0) "" [5]=> string(0) "" ["user"]=> string(0) "" [6]=> string(0) "" ["pass"]=> string(0) "" [7]=> string(0) "" ["host"]=> string(11) "example.org" [8]=> string(11) "example.org" ["host_name"]=> string(11) "example.org" [9]=> string(11) "example.org" ["ipv4"]=> string(0) "" [10]=> string(0) "" ["ipv6"]=> string(0) "" [11]=> string(0) "" ["port"]=> string(0) "" [12]=> string(0) "" ["path"]=> string(55) "/scheme-relative/URI/with/absolute/path/to/resource.txt" [13]=> string(55) "/scheme-relative/URI/with/absolute/path/to/resource.txt" } array(29) { [0]=> string(48) "/relative/URI/with/absolute/path/to/resource.txt" ["slash_seg"]=> string(0) "" [1]=> string(0) "" ["pchar"]=> string(0) "" [2]=> string(0) "" ["queryfrag"]=> string(0) "" [3]=> string(0) "" ["scheme"]=> string(0) "" [4]=> string(0) "" ["userinfo"]=> string(0) "" [5]=> string(0) "" ["user"]=> string(0) "" [6]=> string(0) "" ["pass"]=> string(0) "" [7]=> string(0) "" ["host"]=> string(0) "" [8]=> string(0) "" ["host_name"]=> string(0) "" [9]=> string(0) "" ["ipv4"]=> string(0) "" [10]=> string(0) "" ["ipv6"]=> string(0) "" [11]=> string(0) "" ["port"]=> string(0) "" [12]=> string(0) "" ["path"]=> string(0) "" [13]=> string(0) "" ["path_abs"]=> string(48) "/relative/URI/with/absolute/path/to/resource.txt" [14]=> string(48) "/relative/URI/with/absolute/path/to/resource.txt" } array(31) { [0]=> string(29) "relative/path/to/resource.txt" ["slash_seg"]=> string(0) "" [1]=> string(0) "" ["pchar"]=> string(0) "" [2]=> string(0) "" ["queryfrag"]=> string(0) "" [3]=> string(0) "" ["scheme"]=> string(0) "" [4]=> string(0) "" ["userinfo"]=> string(0) "" [5]=> string(0) "" ["user"]=> string(0) "" [6]=> string(0) "" ["pass"]=> string(0) "" [7]=> string(0) "" ["host"]=> string(0) "" [8]=> string(0) "" ["host_name"]=> string(0) "" [9]=> string(0) "" ["ipv4"]=> string(0) "" [10]=> string(0) "" ["ipv6"]=> string(0) "" [11]=> string(0) "" ["port"]=> string(0) "" [12]=> string(0) "" ["path"]=> string(0) "" [13]=> string(0) "" ["path_abs"]=> string(0) "" [14]=> string(0) "" ["path_rel"]=> string(29) "relative/path/to/resource.txt" [15]=> string(29) "relative/path/to/resource.txt" } array(31) { [0]=> string(21) "../../../resource.txt" ["slash_seg"]=> string(0) "" [1]=> string(0) "" ["pchar"]=> string(0) "" [2]=> string(0) "" ["queryfrag"]=> string(0) "" [3]=> string(0) "" ["scheme"]=> string(0) "" [4]=> string(0) "" ["userinfo"]=> string(0) "" [5]=> string(0) "" ["user"]=> string(0) "" [6]=> string(0) "" ["pass"]=> string(0) "" [7]=> string(0) "" ["host"]=> string(0) "" [8]=> string(0) "" ["host_name"]=> string(0) "" [9]=> string(0) "" ["ipv4"]=> string(0) "" [10]=> string(0) "" ["ipv6"]=> string(0) "" [11]=> string(0) "" ["port"]=> string(0) "" [12]=> string(0) "" ["path"]=> string(0) "" [13]=> string(0) "" ["path_abs"]=> string(0) "" [14]=> string(0) "" ["path_rel"]=> string(21) "../../../resource.txt" [15]=> string(21) "../../../resource.txt" } array(35) { [0]=> string(21) "./resource.txt#frag01" ["slash_seg"]=> string(0) "" [1]=> string(0) "" ["pchar"]=> string(0) "" [2]=> string(0) "" ["queryfrag"]=> string(0) "" [3]=> string(0) "" ["scheme"]=> string(0) "" [4]=> string(0) "" ["userinfo"]=> string(0) "" [5]=> string(0) "" ["user"]=> string(0) "" [6]=> string(0) "" ["pass"]=> string(0) "" [7]=> string(0) "" ["host"]=> string(0) "" [8]=> string(0) "" ["host_name"]=> string(0) "" [9]=> string(0) "" ["ipv4"]=> string(0) "" [10]=> string(0) "" ["ipv6"]=> string(0) "" [11]=> string(0) "" ["port"]=> string(0) "" [12]=> string(0) "" ["path"]=> string(0) "" [13]=> string(0) "" ["path_abs"]=> string(0) "" [14]=> string(0) "" ["path_rel"]=> string(14) "./resource.txt" [15]=> string(14) "./resource.txt" ["query"]=> string(0) "" [16]=> string(0) "" ["fragment"]=> string(6) "frag01" [17]=> string(6) "frag01" } array(31) { [0]=> string(12) "resource.txt" ["slash_seg"]=> string(0) "" [1]=> string(0) "" ["pchar"]=> string(0) "" [2]=> string(0) "" ["queryfrag"]=> string(0) "" [3]=> string(0) "" ["scheme"]=> string(0) "" [4]=> string(0) "" ["userinfo"]=> string(0) "" [5]=> string(0) "" ["user"]=> string(0) "" [6]=> string(0) "" ["pass"]=> string(0) "" [7]=> string(0) "" ["host"]=> string(0) "" [8]=> string(0) "" ["host_name"]=> string(0) "" [9]=> string(0) "" ["ipv4"]=> string(0) "" [10]=> string(0) "" ["ipv6"]=> string(0) "" [11]=> string(0) "" ["port"]=> string(0) "" [12]=> string(0) "" ["path"]=> string(0) "" [13]=> string(0) "" ["path_abs"]=> string(0) "" [14]=> string(0) "" ["path_rel"]=> string(12) "resource.txt" [15]=> string(12) "resource.txt" } array(35) { [0]=> string(7) "#frag01" ["slash_seg"]=> string(0) "" [1]=> string(0) "" ["pchar"]=> string(0) "" [2]=> string(0) "" ["queryfrag"]=> string(0) "" [3]=> string(0) "" ["scheme"]=> string(0) "" [4]=> string(0) "" ["userinfo"]=> string(0) "" [5]=> string(0) "" ["user"]=> string(0) "" [6]=> string(0) "" ["pass"]=> string(0) "" [7]=> string(0) "" ["host"]=> string(0) "" [8]=> string(0) "" ["host_name"]=> string(0) "" [9]=> string(0) "" ["ipv4"]=> string(0) "" [10]=> string(0) "" ["ipv6"]=> string(0) "" [11]=> string(0) "" ["port"]=> string(0) "" [12]=> string(0) "" ["path"]=> string(0) "" [13]=> string(0) "" ["path_abs"]=> string(0) "" [14]=> string(0) "" ["path_rel"]=> string(0) "" [15]=> string(0) "" ["query"]=> string(0) "" [16]=> string(0) "" ["fragment"]=> string(6) "frag01" [17]=> string(6) "frag01" } array(31) { [0]=> string(0) "" ["slash_seg"]=> string(0) "" [1]=> string(0) "" ["pchar"]=> string(0) "" [2]=> string(0) "" ["queryfrag"]=> string(0) "" [3]=> string(0) "" ["scheme"]=> string(0) "" [4]=> string(0) "" ["userinfo"]=> string(0) "" [5]=> string(0) "" ["user"]=> string(0) "" [6]=> string(0) "" ["pass"]=> string(0) "" [7]=> string(0) "" ["host"]=> string(0) "" [8]=> string(0) "" ["host_name"]=> string(0) "" [9]=> string(0) "" ["ipv4"]=> string(0) "" [10]=> string(0) "" ["ipv6"]=> string(0) "" [11]=> string(0) "" ["port"]=> string(0) "" [12]=> string(0) "" ["path"]=> string(0) "" [13]=> string(0) "" ["path_abs"]=> string(0) "" [14]=> string(0) "" ["path_rel"]=> string(0) "" [15]=> string(0) "" }
Output for 4.4.3 - 4.4.9, 5.1.0 - 5.1.1, 5.1.3 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/4So3Z on line 39
Process exited with code 255.
Output for 4.4.2, 5.1.2
Parse error: syntax error, unexpected '[' in /in/4So3Z on line 40
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/4So3Z on line 39
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/4So3Z on line 39
Process exited with code 255.