3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $expr = '! ^ (?: (?P<scheme> [a-z][a-z0-9.]* ) : )? (?: // (?<authority> (?: (?P<user> [^:@]+ ) (?: : (?P<pass> [^@]+ ) )? @ )? (?P<host> [^:/]+ ) (?: : (?P<port> [0-9]+ ) )? ) )? (?: / (?P<path> /[^?#]+ ) )? (?: \? (?P<query> [^#]+ ) )? (?: # (?P<fragment> .+ ) )? $ !ix'; $urls = [ 'http://host.com/path', 'http://user@host.com/path', 'http://user:pass@host.com/path', 'http://user:pass@host.com:8080/path', '//user:pass@host.com:8080/path', 'http://user:pass@host.com:8080/path?query#fragment', ]; foreach ($urls as $str) { echo "$str\n"; preg_match($expr, $str, $matches); var_dump($matches); }
Output for 5.4.0 - 5.6.28, hhvm-3.12.0, 7.0.0 - 7.1.0
http://host.com/path array(19) { [0]=> string(20) "http://host.com/path" ["scheme"]=> string(4) "http" [1]=> string(4) "http" ["authority"]=> string(8) "host.com" [2]=> string(8) "host.com" ["user"]=> string(0) "" [3]=> string(0) "" ["pass"]=> string(0) "" [4]=> string(0) "" ["host"]=> string(8) "host.com" [5]=> string(8) "host.com" ["port"]=> string(0) "" [6]=> string(0) "" ["path"]=> string(0) "" [7]=> string(0) "" ["query"]=> string(0) "" [8]=> string(0) "" ["fragment"]=> string(5) "/path" [9]=> string(5) "/path" } http://user@host.com/path array(19) { [0]=> string(25) "http://user@host.com/path" ["scheme"]=> string(4) "http" [1]=> string(4) "http" ["authority"]=> string(13) "user@host.com" [2]=> string(13) "user@host.com" ["user"]=> string(4) "user" [3]=> string(4) "user" ["pass"]=> string(0) "" [4]=> string(0) "" ["host"]=> string(8) "host.com" [5]=> string(8) "host.com" ["port"]=> string(0) "" [6]=> string(0) "" ["path"]=> string(0) "" [7]=> string(0) "" ["query"]=> string(0) "" [8]=> string(0) "" ["fragment"]=> string(5) "/path" [9]=> string(5) "/path" } http://user:pass@host.com/path array(19) { [0]=> string(30) "http://user:pass@host.com/path" ["scheme"]=> string(4) "http" [1]=> string(4) "http" ["authority"]=> string(18) "user:pass@host.com" [2]=> string(18) "user:pass@host.com" ["user"]=> string(4) "user" [3]=> string(4) "user" ["pass"]=> string(4) "pass" [4]=> string(4) "pass" ["host"]=> string(8) "host.com" [5]=> string(8) "host.com" ["port"]=> string(0) "" [6]=> string(0) "" ["path"]=> string(0) "" [7]=> string(0) "" ["query"]=> string(0) "" [8]=> string(0) "" ["fragment"]=> string(5) "/path" [9]=> string(5) "/path" } http://user:pass@host.com:8080/path array(19) { [0]=> string(35) "http://user:pass@host.com:8080/path" ["scheme"]=> string(4) "http" [1]=> string(4) "http" ["authority"]=> string(23) "user:pass@host.com:8080" [2]=> string(23) "user:pass@host.com:8080" ["user"]=> string(4) "user" [3]=> string(4) "user" ["pass"]=> string(4) "pass" [4]=> string(4) "pass" ["host"]=> string(8) "host.com" [5]=> string(8) "host.com" ["port"]=> string(4) "8080" [6]=> string(4) "8080" ["path"]=> string(0) "" [7]=> string(0) "" ["query"]=> string(0) "" [8]=> string(0) "" ["fragment"]=> string(5) "/path" [9]=> string(5) "/path" } //user:pass@host.com:8080/path array(19) { [0]=> string(30) "//user:pass@host.com:8080/path" ["scheme"]=> string(0) "" [1]=> string(0) "" ["authority"]=> string(23) "user:pass@host.com:8080" [2]=> string(23) "user:pass@host.com:8080" ["user"]=> string(4) "user" [3]=> string(4) "user" ["pass"]=> string(4) "pass" [4]=> string(4) "pass" ["host"]=> string(8) "host.com" [5]=> string(8) "host.com" ["port"]=> string(4) "8080" [6]=> string(4) "8080" ["path"]=> string(0) "" [7]=> string(0) "" ["query"]=> string(0) "" [8]=> string(0) "" ["fragment"]=> string(5) "/path" [9]=> string(5) "/path" } http://user:pass@host.com:8080/path?query#fragment array(19) { [0]=> string(50) "http://user:pass@host.com:8080/path?query#fragment" ["scheme"]=> string(4) "http" [1]=> string(4) "http" ["authority"]=> string(23) "user:pass@host.com:8080" [2]=> string(23) "user:pass@host.com:8080" ["user"]=> string(4) "user" [3]=> string(4) "user" ["pass"]=> string(4) "pass" [4]=> string(4) "pass" ["host"]=> string(8) "host.com" [5]=> string(8) "host.com" ["port"]=> string(4) "8080" [6]=> string(4) "8080" ["path"]=> string(0) "" [7]=> string(0) "" ["query"]=> string(0) "" [8]=> string(0) "" ["fragment"]=> string(20) "/path?query#fragment" [9]=> string(20) "/path?query#fragment" }
Output for hhvm-3.10.0

Process exited with code 153.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/k6NSO on line 42
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/k6NSO on line 42
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/k6NSO on line 42
Process exited with code 255.