3v4l.org

run code in 300+ PHP versions simultaneously
<?php class URI { public static function getRegex() { static $cache; if ($cache) return $cache; ################################################################################### # # pct-encoded := "%" HEXDIG HEXDIG # unreserved := ALPHA / DIGIT / "-" / "." / "_" / "~" # reserved := gen-delims / sub-delims # gen-delims := "#" / "/" / ":" / "?" / "@" / "[" / "]" # sub-delims := "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" # pchar := unreserved / pct-encoded / sub-delims / ":" / "@" $pct_encoded = '\x25[0-9A-Fa-f][0-9A-Fa-f]'; $unreserved = '[\x2d\x2e\x30-\x39\x41-\x5a\x5f\x61-\x7a\x7e\p{L}]'; $gen_dims = '[\x23\x2f\x3a\x3f]'; $sub_delims = '[\x21\x24\x26-\x2c\x3b\x3d\x40\x5b\x5d]'; $reserved = '[\x21\x23\x24\x26-\x2c\x2f\x3a\x3b\x3d\x3f\x40\x5b\x5d]'; $pchar = "(?:[\\x21\\x24\\x26-\\x2e\\x30-\\x3b\\x3d\\x40-\\x5a\\x5f\\x61-\\x7a\\x7e\\p{L}]|$pct_encoded)"; ################################################################################# # # segment := *pchar # segment-nz := 1*pchar # segment-nz-nc := 1*(unreserved / pct-encoded / sub-delims / "@") # ; non-zero-length segment without any colon ":" $segment = "$pchar*"; $segment_nz = "$pchar+"; $segment_nx_nc = "(?:$unreserve|$pct_encoded|$sub_delims|\\x40)+"; ################################################################################# # # path-abempty := *( "/" segment ) # path-absolute := "/" [ segment-nz *( "/" segment ) ] # path-noscheme := segment-nz-nc *( "/" segment ) # path-rootless := segment-nz *( "/" segment ) # path-empty := 0<pchar> $path_abempty = "(P<Path>(?:\\x2f$segment)*)"; $path_absolute = "(P<Path>\\x2f(?:$segment(?:\\x2f$segment)*)?)"; $path_noscheme = "(P<Path>$setment_nz_nc(?:\\x2f$segment)*)"; $path_rootless = "(P<Path>$segment_nz(?:\\x2f$segment)*)"; $path_empty = "(P<Path>)"; ################################################################################## # # IP-literal := "[" (IPv6address / IPvFuture) "]" # # IPvFuture := "v" 1*HEXDIG "." 1*(unreserved / sub-delims / ":") # # IPv6address := 6(h16 ":") ls32 # / "::" 5(h16 ":") ls32 # / [h16] "::" 4(h16 ":") ls32 # / [*1(h16 ":") h16] "::" 3(h16 ":") ls32 # / [*2( h16 ":") h16] "::" 2(h16 ":") ls32 # / [*3(h16 ":") h16] "::" h16 ":" ls32 # / [*4(h16 ":") h16] "::" ls32 # / [*5(h16 ":") h16] "::" h16 # / [*6(h16 ":") h16] "::" # # IPv4address := dec-octet "." dec-octet "." dec-octet "." dec-octet # # h16 := 1*4HEXDIG # ls32 := (h16 ":" h16) / IPv4address # dec-octet := DIGIT ; 0-9 # / %x31-39 DIGIT ; 10-99 # / "1" 2DIGIT ; 100-199 # / "2" %x30-34 DIGIT ; 200-249 # / "25" %x30-35 ; 250-255 $dec_octet = '(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]'; $IPv4Address = "(P<IPv4Address>$dec_octet\\x2e$dec_octet\\x2e$dec_octet\\x2e$dec_octet)"; $h16 = '[0-9A-Fa-f]{1,4}'; $ls32 = "(?:$h16\\x3a$h16|$IPv4Address)"; $IPv6Address = "(P<IPv6Address>" . "(?:$h16\\x3a){6}$ls32|" . "\\x3a\\x3a(?:$h16\\x3a){5}$ls32|" . "(?:$h16)?\\x3a\\x3a(?:$h16\\x3a){5}$ls32|" . "(?:(?:$h16\\x3a){,1}$h16)?\\x3a\\x3a(?:$h16\\x3a){3}$ls32|" . "(?:(?:$h16\\x3a){,2}$h16)?\\x3a\\x3a(?:$h16\\x3a){2}$ls32|" . "(?:(?:$h16\\x3a){,3}$h16)?\\x3a\\x3a(?:$h16\\x3a){1}$ls32|" . "(?:(?:$h16\\x3a){,4}$h16)?\\x3a\\x3a$ls32|" . "(?:(?:$h16\\x3a){,5}$h16)?\\x3a\\x3a$h16|" . "(?:(?:$h16\\x3a){,6}$h16)?\\x3a\\x3a" . ")"; $IPvFuture = "v[0-9A-Fa-f]+\\x2e(?:$unreserved|$sub_delims|\\x3a)"; $IPvLiteral = "(?:\\x5b$IPv6Address|$IPvFuture\\x5d)"; ################################################################################ # # reg-name := *(unreserved / pct-encoded / sub-delims) $reg_name = "(?:$unreserved|$pct_encoded|$sub_delims)*"; ################################################################################ # # authority := [userinfo "@"] host [":" port] # userinfo := *(unreserved / pct-encoded / sub-delims / ":") # host := IP-literal / IPv4address / reg-name # port := *DIGIT $userninfo = "(P<Userinfo>(?:$unreserved|$pct_encoded|$sub_delims|\\x3a)*)"; $host = "(P<Host>$reg_name|$IPvLiteral|$IPv4Address)"; $port = "(P<Port>[0-9]*)"; $authoritry = "(?:$userinfo\\x40)?$host(?:\\x3a$port)?"; ################################################################################ # # scheme := ALPHA *(ALPHA / DIGIT / "+" / "-" / ".") # hier-part := "//" authority path-abempty # / path-absolute # / path-rootless # / path-empty # # relative-part := "//" authority path-abempty # / path-absolute # / path-rootless # / path-empty # query := *(pchar / "/" / "?") # fragment := *(pchar / "/" / "?") $scheme = '(P<Scheme>[A-Za-z][\x2b\x2d\x2e0-9A-Za-z]*)'; $hier_part = "(?:\\x2f\\x2f$authority$path_abemtpy|$path_absolute|$path_rootless|$path_empty)"; $relative_part = "(?:\\x2f\\x2f$authority$path_abemtpy|$path_absolute|$path_noscheme|$path_empty)"; $query = "(P<Query>(?:$pchar|\x2f|\x3f)*)"; $fragment = "(P<Fragment>(?:$pchar|\x2f|\x3f)*)"; ################################################################################ # # URI-reference := URI / relative-ref # # URI := scheme ":" hier-part ["?" query] ["#" fragment] # # relative-ref := relative-part ["?" query] ["#" fragment] $URI = "(?:$scheme\\x3a$hier_part(?:\\x3f$query)?(?:\\x23$fragment)?"; $relative_ref = "$relative_part(?:\\x3f$query)?(?:\\x23$fragment)?"; $URI_spec = "(P<URI>:$URI|$relative_ref)"; return $cache = $URI_spec; } /** * Resolves dot segments in a path. * * <h3>Introduction</h3> * * <p>This function takes a valid url path and nomalizes it into * the simplest form possible.</p> * * <hr> * * @throws \BLW\Model\InvalidArgumentException If <code>$Path</code> is not a string or is empty. * * @param string $Path Path to normalize. * @param bool $isRelative Whether path is relative or absolute. * @return string Normailized path. */ public static function removeDotSegments($Path, $isRelative = false) { # Not a string or empty if (is_string($Path)? !empty($Path) : false) { # Does path start with "/" $isAbsolute = $Path[0] == '/'; # Does path end with "/" $isTrailingSlash = $Path[strlen($Path) - 1] == '/'; # Split path into segments $Segments = array_values(array_filter(explode("/", $Path), function($v) {return !!$v;})); # Go through parts and resolve dots ("." & "..") for ($up=0, $i=count($Segments)-1; $i>=0; $i--) { # Part is a single dot if ($Segments[$i] == '.') { # Remove it unset($Segments[$i]); } # Part is a double dot elseif ($Segments[$i] == '..') { # Remove it unset($Segments[$i]); # Move up $up++; } # Part is a directory / file else { # did we move up? if ($up) { # Remove it unset($Segments[$i]); #move down $up--; } } } # Recreate path if ($isRelative) { $Path = str_repeat('../', $up) . implode('/', $Segments); } else { $Path = implode('/', $Segments); } # Check results if (empty($Path) && !$isAbsolute) $Path = ''; # Restore trailing slash if (!empty($Path) && $isTrailingSlash) $Path .= '/'; # Restore starting slash if ($isAbsolute) $Path = '/' . $Path; # Done return $Path; } # Path is empty or not a string else throw new InvalidArgumentException(0); # Done return ''; } public static function parse($URI) { # Default return value $return = array( 'Scheme' => '' ,'Userinfo' => '' ,'Host' => '' ,'Port' => '' ,'Path' => '' ,'Query' => '' ,'Fragment' => '' ,'IPv4Address' => '' ,'IPv6Address' => '' ); # Is URI a string? if (is_string($URL) ?: is_callable(array($URI, '__toString'))) { # Run regex if (preg_match('!^'. self::getRegex() .'$!', $URI, $m)) { var_dump($m); } } # Invalid URI else throw new InvalidArgumentException(0); # Done return $return; } } $Test = array( 'ftp://ftp.is.co.za/rfc/rfc1808.txt' ,'http://www.ietf.org/rfc/rfc2396.txt' ,'ldap://[2001:db8::7]/c=GB?objectClass?one' ,'mailto:John.Doe@example.com' ,'news:comp.infosystems.www.servers.unix' ,'tel:+1-816-555-1212' ,'telnet://192.0.2.16:80/' ,'urn:oasis:names:specification:docbook:dtd:xml:4.1.2' ); foreach ($Test as $URI) { URI::parse($URI); }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.40.0070.00718.92
8.3.30.0030.01719.18
8.3.20.0040.00420.32
8.3.10.0040.00421.91
8.3.00.0000.00822.51
8.2.170.0070.00722.96
8.2.160.0140.00019.38
8.2.150.0080.00024.18
8.2.140.0060.00324.66
8.2.130.0080.00026.16
8.2.120.0060.00319.61
8.2.110.0030.00719.39
8.2.100.0080.00418.03
8.2.90.0000.00817.88
8.2.80.0030.00717.97
8.2.70.0080.00018.16
8.2.60.0040.00418.05
8.2.50.0030.00618.29
8.2.40.0030.00520.60
8.2.30.0000.00818.21
8.2.20.0000.00817.91
8.2.10.0030.00617.89
8.2.00.0000.00818.00
8.1.270.0040.00422.23
8.1.260.0070.00026.35
8.1.250.0040.00428.09
8.1.240.0090.00322.12
8.1.230.0110.00020.94
8.1.220.0040.00417.91
8.1.210.0040.00418.77
8.1.200.0030.00617.48
8.1.190.0060.00317.35
8.1.180.0030.00518.10
8.1.170.0090.00018.78
8.1.160.0030.00622.31
8.1.150.0030.00618.81
8.1.140.0050.00317.46
8.1.130.0030.00317.89
8.1.120.0030.00517.66
8.1.110.0040.00417.45
8.1.100.0040.00417.49
8.1.90.0050.00217.46
8.1.80.0020.00517.48
8.1.70.0000.00717.61
8.1.60.0050.00317.60
8.1.50.0000.00817.54
8.1.40.0000.00817.61
8.1.30.0050.00317.65
8.1.20.0030.00517.74
8.1.10.0080.00017.70
8.1.00.0040.00417.59
8.0.300.0060.00320.01
8.0.290.0090.00017.00
8.0.280.0070.00018.54
8.0.270.0040.00417.38
8.0.260.0030.00316.95
8.0.250.0070.00017.07
8.0.240.0000.00817.15
8.0.230.0000.00717.04
8.0.220.0080.00016.97
8.0.210.0070.00017.13
8.0.200.0000.00817.16
8.0.190.0080.00017.19
8.0.180.0000.00717.00
8.0.170.0000.00717.10
8.0.160.0040.00417.06
8.0.150.0030.00517.05
8.0.140.0070.00017.07
8.0.130.0000.00613.48
8.0.120.0080.00017.10
8.0.110.0000.00717.15
8.0.100.0000.00717.02
8.0.90.0050.00317.00
8.0.80.0060.00916.99
8.0.70.0080.00016.95
8.0.60.0000.00817.06
8.0.50.0050.00317.09
8.0.30.0060.01317.04
8.0.20.0120.00717.56
8.0.10.0050.00217.17
8.0.00.0070.01116.98
7.4.330.0050.00015.00
7.4.320.0000.00716.74
7.4.300.0000.00616.49
7.4.290.0030.00316.54
7.4.280.0000.00816.74
7.4.270.0070.00016.74
7.4.260.0000.00716.72
7.4.250.0080.00016.62
7.4.240.0040.00416.76
7.4.230.0030.00416.39
7.4.220.0090.00916.73
7.4.210.0050.01216.64
7.4.200.0040.00416.57
7.4.190.0000.00716.90
7.4.160.0120.00416.64
7.4.150.0070.01117.40
7.4.140.0060.01717.86
7.4.130.0090.00916.67
7.4.120.0100.00716.71
7.4.110.0080.00916.64
7.4.100.0090.00916.68
7.4.90.0080.01516.51
7.4.80.0130.00319.39
7.4.70.0170.01016.53
7.4.60.0170.00316.56
7.4.50.0020.00516.63
7.4.40.0020.01022.77
7.4.30.0040.01216.71
7.4.00.0030.01014.93
7.3.330.0000.00513.56
7.3.320.0030.00313.47
7.3.310.0040.00416.39
7.3.300.0030.00316.46
7.3.290.0030.01016.51
7.3.280.0110.00816.49
7.3.270.0090.00917.40
7.3.260.0090.00916.74
7.3.250.0100.00916.68
7.3.240.0100.01616.55
7.3.230.0120.00616.45
7.3.210.0100.00716.55
7.3.200.0070.01119.39
7.3.190.0090.00916.59
7.3.180.0060.01016.48
7.3.170.0070.01016.43
7.3.160.0130.01016.70
7.3.120.0100.00615.21
7.2.330.0150.00316.84
7.2.320.0270.01916.58
7.2.310.0120.01216.82
7.2.300.0160.00616.94
7.2.290.0040.01516.90
7.2.60.0000.01416.70
7.2.00.0060.00619.45
7.1.200.0000.01115.86
7.1.70.0060.00317.16
7.1.60.0060.00616.89
7.1.50.0110.01534.86
7.1.00.0030.07722.33
7.0.200.0060.01016.82
7.0.140.0070.07022.22
7.0.100.0100.07320.07
7.0.90.0170.06720.06
7.0.80.0170.07020.03
7.0.70.0170.08720.04
7.0.60.0000.08720.07
7.0.50.0130.07320.40
7.0.40.0100.08020.18
7.0.30.0030.08320.05
7.0.20.0200.07020.09
7.0.10.0130.08020.06
7.0.00.0100.05720.14
5.6.280.0030.07320.82
5.6.250.0130.06720.74
5.6.240.0100.07720.69
5.6.230.0100.05020.71
5.6.220.0030.08720.73
5.6.210.0200.07020.71
5.6.200.0100.08321.18
5.6.190.0170.07021.09
5.6.180.0100.04321.15
5.6.170.0230.06721.07
5.6.160.0100.08021.22
5.6.150.0070.08021.23
5.6.140.0170.07721.13
5.6.130.0100.09021.09
5.6.120.0130.08021.16
5.6.110.0070.08321.13
5.6.100.0000.08021.00
5.6.90.0170.07320.96
5.6.80.0070.08720.52
5.6.70.0070.08020.57
5.6.60.0000.06720.54
5.6.50.0070.07720.48
5.6.40.0000.09020.42
5.6.30.0000.08720.47
5.6.20.0170.06720.52
5.6.10.0030.07320.42
5.6.00.0070.05320.38
5.5.380.0100.08020.40
5.5.370.0070.07720.56
5.5.360.0070.05320.40
5.5.350.0100.07720.50
5.5.340.0070.05720.97
5.5.330.0030.08320.98
5.5.320.0070.08720.83
5.5.310.0130.08720.85
5.5.300.0100.08020.95
5.5.290.0170.08020.66
5.5.280.0100.08320.92
5.5.270.0100.04720.92
5.5.260.0100.07720.87
5.5.250.0070.08320.76
5.5.240.0000.08720.33
5.5.230.0130.07320.24
5.5.220.0130.07320.23
5.5.210.0100.07720.36
5.5.200.0100.08020.32
5.5.190.0130.07020.32
5.5.180.0100.08020.24
5.5.160.0130.07320.32
5.5.150.0200.07020.20
5.5.140.0030.07020.23
5.5.130.0270.02720.33
5.5.120.0070.04720.32
5.5.110.0130.06720.03
5.5.100.0070.04020.21
5.5.90.0030.08020.08
5.5.80.0070.08020.13
5.5.70.0030.07320.21
5.5.60.0030.07320.08
5.5.50.0070.07320.20
5.5.40.0000.08720.19
5.5.30.0100.07320.16
5.5.20.0170.06320.20
5.5.10.0070.08020.07
5.5.00.0130.07320.18
5.4.450.0070.04019.38
5.4.440.0070.05319.37
5.4.430.0030.08319.47
5.4.420.0070.08019.38
5.4.410.0130.05019.27
5.4.400.0170.07319.09
5.4.390.0100.05319.09
5.4.380.0100.08718.88
5.4.370.0030.07719.11
5.4.360.0070.08019.09
5.4.350.0170.06719.04
5.4.340.0130.06319.03
5.4.320.0070.04719.20
5.4.310.0030.08019.17
5.4.300.0130.06719.12
5.4.290.0070.06319.20
5.4.280.0070.08019.17
5.4.270.0070.07318.95
5.4.260.0070.07719.04
5.4.250.0100.06319.17
5.4.240.0030.06718.90
5.4.230.0070.04319.04
5.4.220.0130.07319.23
5.4.210.0000.07719.04
5.4.200.0030.08019.12
5.4.190.0030.07319.04
5.4.180.0070.07719.11
5.4.170.0070.08019.11
5.4.160.0100.07719.02
5.4.150.0130.07019.15
5.4.140.0030.08016.46
5.4.130.0070.06716.19
5.4.120.0100.06316.46
5.4.110.0130.05716.50
5.4.100.0070.07316.55
5.4.90.0100.06716.39
5.4.80.0100.07316.46
5.4.70.0030.06316.37
5.4.60.0100.04316.37
5.4.50.0070.06716.52
5.4.40.0000.08016.53
5.4.30.0000.04316.34
5.4.20.0070.03016.36
5.4.10.0070.03016.53
5.4.00.0030.05715.86
5.3.290.0100.07314.70
5.3.280.0030.04314.67
5.3.270.0100.07314.73
5.3.260.0100.07714.78
5.3.250.0070.04314.70
5.3.240.0130.07314.79
5.3.230.0030.07714.75
5.3.220.0100.07714.56
5.3.210.0070.04714.61
5.3.200.0170.05014.55
5.3.190.0070.07314.58
5.3.180.0100.06314.60
5.3.170.0000.08314.61
5.3.160.0100.07014.59
5.3.150.0030.06314.68
5.3.140.0030.04014.62
5.3.130.0000.08714.71
5.3.120.0070.07714.64
5.3.110.0100.04314.70
5.3.100.0070.07714.15
5.3.90.0130.06714.18
5.3.80.0070.06713.97
5.3.70.0100.07014.08
5.3.60.0070.07314.15
5.3.50.0070.07713.90
5.3.40.0000.06714.07
5.3.30.0030.04013.99
5.3.20.0070.08013.79
5.3.10.0030.06713.69
5.3.00.0100.06313.73

preferences:
41.69 ms | 400 KiB | 5 Q