3v4l.org

run code in 300+ PHP versions simultaneously
<?php function ip_in_range($ip, $range) { $array_range = array(); if(strpos($range, ",") !== false) { // Varias faixas de ip $return = true; $array_range = explode(",", $range); foreach ($array_range as $rangeIP) { echo $rangeIP."\n"; if($rangeIP){ echo "1"."\n"; if($ip != $rangeIP){ echo "2"."\n"; $return = false; break; } else if (strpos($rangeIP, '/') !== false) { echo "3"."\n"; // $rangeIP is in IP/NETMASK format list($rangeIP, $netmask) = explode('/', $rangeIP, 2); if (strpos($netmask, '.') !== false) { echo "4"."\n"; // $netmask is a 255.255.0.0 format $netmask = str_replace('*', '0', $netmask); $netmask_dec = ip2long($netmask); $return = ( (ip2long($ip) & $netmask_dec) == (ip2long($rangeIP) & $netmask_dec) ); if(!$return) { echo "5"."\n"; break; } } else { echo "6"."\n"; // $netmask is a CIDR size block // fix the rangeIP argument $x = explode('.', $rangeIP); while(count($x)<4) $x[] = '0'; list($a,$b,$c,$d) = $x; $rangeIP = sprintf("%u.%u.%u.%u", empty($a)?'0':$a, empty($b)?'0':$b,empty($c)?'0':$c,empty($d)?'0':$d); $range_dec = ip2long($rangeIP); $ip_dec = ip2long($ip); # Strategy 1 - Create the netmask with 'netmask' 1s and then fill it to 32 with 0s #$netmask_dec = bindec(str_pad('', $netmask, '1') . str_pad('', 32-$netmask, '0')); # Strategy 2 - Use math to create it $wildcard_dec = pow(2, (32-$netmask)) - 1; $netmask_dec = ~ $wildcard_dec; $return = (($ip_dec & $netmask_dec) == ($range_dec & $netmask_dec)); if(!$return) { echo "7"."\n"; break; } } } else { echo "8"."\n"; // rangeIP might be 255.255.*.* or 1.2.3.0-1.2.3.255 if (strpos($rangeIP, '*') !== false) { // a.b.*.* format echo "9"."\n"; // Just convert to A-B format by setting * to 0 for A and 255 for B $lower = str_replace('*', '0', $rangeIP); $upper = str_replace('*', '255', $rangeIP); $rangeIP = "$lower-$upper"; } if (strpos($rangeIP, '-') !== false) { // A-B format echo "10"."\n"; list($lower, $upper) = explode('-', $rangeIP, 2); $lower_dec = (float)sprintf("%u",ip2long($lower)); $upper_dec = (float)sprintf("%u",ip2long($upper)); $ip_dec = (float)sprintf("%u",ip2long($ip)); $return = ( ($ip_dec>=$lower_dec) && ($ip_dec<=$upper_dec) ); if(!$return) { echo "11"."\n"; break; } } echo "12"."\n"; $return = false; break; } } } echo "13"."\n"; return $return; } else { // Uma faixas de ip if(!$range){ return true; } else if($ip == $range){ return true; } else if (strpos($range, '/') !== false) { // $range is in IP/NETMASK format list($range, $netmask) = explode('/', $range, 2); if (strpos($netmask, '.') !== false) { // $netmask is a 255.255.0.0 format $netmask = str_replace('*', '0', $netmask); $netmask_dec = ip2long($netmask); return ( (ip2long($ip) & $netmask_dec) == (ip2long($range) & $netmask_dec) ); } else { // $netmask is a CIDR size block // fix the range argument $x = explode('.', $range); while(count($x)<4) $x[] = '0'; list($a,$b,$c,$d) = $x; $range = sprintf("%u.%u.%u.%u", empty($a)?'0':$a, empty($b)?'0':$b,empty($c)?'0':$c,empty($d)?'0':$d); $range_dec = ip2long($range); $ip_dec = ip2long($ip); # Strategy 1 - Create the netmask with 'netmask' 1s and then fill it to 32 with 0s #$netmask_dec = bindec(str_pad('', $netmask, '1') . str_pad('', 32-$netmask, '0')); # Strategy 2 - Use math to create it $wildcard_dec = pow(2, (32-$netmask)) - 1; $netmask_dec = ~ $wildcard_dec; return (($ip_dec & $netmask_dec) == ($range_dec & $netmask_dec)); } } else { // range might be 255.255.*.* or 1.2.3.0-1.2.3.255 if (strpos($range, '*') !==false) { // a.b.*.* format // Just convert to A-B format by setting * to 0 for A and 255 for B $lower = str_replace('*', '0', $range); $upper = str_replace('*', '255', $range); $range = "$lower-$upper"; } if (strpos($range, '-')!==false) { // A-B format list($lower, $upper) = explode('-', $range, 2); $lower_dec = (float)sprintf("%u",ip2long($lower)); $upper_dec = (float)sprintf("%u",ip2long($upper)); $ip_dec = (float)sprintf("%u",ip2long($ip)); return ( ($ip_dec>=$lower_dec) && ($ip_dec<=$upper_dec) ); } return false; } } } echo "\n". (int) ip_in_range("127.0.0.1", "127.0.0.0,127.0.0.1");

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.60.0090.00616.50
8.3.50.0110.00921.97
8.3.40.0040.01118.76
8.3.30.0110.00418.54
8.3.20.0000.00720.38
8.3.10.0000.00823.56
8.3.00.0150.00019.16
8.2.180.0090.00918.17
8.2.170.0090.00622.96
8.2.160.0000.01622.07
8.2.150.0040.00724.18
8.2.140.0040.00424.66
8.2.130.0070.00026.16
8.2.120.0090.00017.63
8.2.110.0060.00322.20
8.2.100.0040.00817.84
8.2.90.0080.00019.22
8.2.80.0060.00317.97
8.2.70.0050.00317.75
8.2.60.0040.00418.16
8.2.50.0080.00018.07
8.2.40.0060.00319.65
8.2.30.0000.00720.78
8.2.20.0040.00417.68
8.2.10.0030.00618.22
8.2.00.0040.00418.29
8.1.280.0120.00625.92
8.1.270.0030.00623.71
8.1.260.0050.00326.35
8.1.250.0040.00428.09
8.1.240.0040.00423.97
8.1.230.0120.00017.95
8.1.220.0060.00317.77
8.1.210.0000.00818.77
8.1.200.0000.00917.35
8.1.190.0000.00817.13
8.1.180.0000.00818.10
8.1.170.0080.00018.84
8.1.160.0040.00422.13
8.1.150.0000.00719.00
8.1.140.0050.00319.74
8.1.130.0000.00717.86
8.1.120.0040.00417.60
8.1.110.0030.00517.46
8.1.100.0050.00217.43
8.1.90.0040.00417.64
8.1.80.0050.00217.66
8.1.70.0000.00717.55
8.1.60.0050.00217.59
8.1.50.0030.00517.57
8.1.40.0050.00317.55
8.1.30.0030.00517.75
8.1.20.0000.00817.75
8.1.10.0000.00817.52
8.1.00.0070.00317.54
8.0.300.0040.00418.77
8.0.290.0060.00316.88
8.0.280.0030.00318.44
8.0.270.0040.00417.44
8.0.260.0030.00317.37
8.0.250.0030.00517.11
8.0.240.0000.00817.04
8.0.230.0000.00717.09
8.0.220.0000.00816.99
8.0.210.0040.00416.88
8.0.200.0040.00417.09
8.0.190.0060.00317.01
8.0.180.0040.00417.02
8.0.170.0040.00416.95
8.0.160.0000.00717.08
8.0.150.0050.00316.91
8.0.140.0040.00416.95
8.0.130.0060.00013.47
8.0.120.0080.00016.94
8.0.110.0000.00717.01
8.0.100.0040.00417.01
8.0.90.0050.00217.07
8.0.80.0100.01017.01
8.0.70.0030.00616.94
8.0.60.0030.00616.98
8.0.50.0040.00416.94
8.0.30.0090.01217.19
8.0.20.0110.01217.40
8.0.10.0080.00017.16
8.0.00.0060.01216.83
7.4.330.0030.00315.08
7.4.320.0040.00416.70
7.4.300.0000.00616.54
7.4.290.0000.00716.68
7.4.280.0040.00416.53
7.4.270.0040.00416.64
7.4.260.0050.00316.70
7.4.250.0040.00416.63
7.4.240.0020.00516.56
7.4.230.0030.00316.53
7.4.220.0110.01216.71
7.4.210.0060.00916.72
7.4.200.0000.00716.47
7.4.160.0110.00516.66
7.4.150.0030.01517.40
7.4.140.0190.00517.86
7.4.130.0100.01016.62
7.4.120.0110.00816.63
7.4.110.0090.00916.66
7.4.100.0120.00616.70
7.4.90.0090.01416.54
7.4.80.0060.01519.39
7.4.70.0180.00016.78
7.4.60.0030.01516.61
7.4.50.0000.00816.63
7.4.40.0120.00616.52
7.4.30.0100.00716.54
7.4.10.0070.00715.28
7.4.00.0050.01115.16
7.3.330.0050.00013.28
7.3.320.0050.00013.25
7.3.310.0030.00316.37
7.3.300.0030.00316.46
7.3.290.0000.00716.30
7.3.280.0080.01016.42
7.3.270.0090.01417.40
7.3.260.0110.01416.58
7.3.250.0110.00816.54
7.3.240.0090.01116.56
7.3.230.0090.00916.42
7.3.210.0100.01016.74
7.3.200.0090.00916.49
7.3.190.0060.01916.46
7.3.180.0040.01416.61
7.3.170.0060.01016.40
7.3.160.0050.01116.63
7.3.130.0110.00614.96
7.3.120.0110.00414.84
7.3.110.0030.01215.20
7.3.100.0040.01115.08
7.3.90.0100.00714.74
7.3.80.0040.00815.23
7.3.70.0060.00615.09
7.3.60.0070.00715.08
7.3.50.0030.00514.81
7.3.40.0000.01514.64
7.3.30.0040.01114.99
7.3.20.0040.01216.84
7.3.10.0110.00416.57
7.3.00.0000.01116.74
7.2.330.0060.01216.89
7.2.320.0220.01116.80
7.2.310.0040.01216.89
7.2.300.0120.00816.78
7.2.290.0090.01216.64
7.2.260.0060.01015.13
7.2.250.0040.01515.27
7.2.240.0100.00715.07
7.2.230.0080.00415.12
7.2.220.0130.00315.01
7.2.210.0040.01115.00
7.2.200.0030.01015.13
7.2.190.0000.01115.04
7.2.180.0110.00415.08
7.2.170.0070.00315.13
7.2.160.0030.01014.89
7.2.150.0000.01416.84
7.2.140.0070.00717.01
7.2.130.0060.01216.67
7.2.120.0030.00617.14
7.2.110.0030.00916.88
7.2.100.0090.00616.72
7.2.90.0000.01117.03
7.2.80.0030.01317.04
7.2.70.0070.00716.94
7.2.60.0080.00516.90
7.2.50.0070.01016.73
7.2.40.0080.00816.82
7.2.30.0000.01416.95
7.2.20.0040.01116.73
7.2.10.0070.01016.75
7.2.00.0060.00818.05
7.1.330.0090.00615.75
7.1.320.0030.01215.79
7.1.310.0030.01015.82
7.1.300.0080.00015.70
7.1.290.0040.00415.52
7.1.280.0030.01015.82
7.1.270.0000.00915.43
7.1.260.0060.00615.57
7.1.250.0090.00615.57
7.1.240.0050.00515.85
7.1.230.0030.00915.79
7.1.220.0080.00615.85
7.1.210.0000.01015.98
7.1.200.0040.00815.71
7.1.190.0040.00415.72
7.1.180.0060.00615.98
7.1.170.0030.01315.95
7.1.160.0070.00715.77
7.1.150.0000.01015.99
7.1.140.0090.00615.94
7.1.130.0140.00015.83
7.1.120.0000.01315.75
7.1.110.0040.00815.66
7.1.100.0060.00916.91
7.1.90.0040.01215.77
7.1.80.0080.00415.87
7.1.70.0000.00916.61
7.1.60.0100.00917.75
7.1.50.0030.01216.48
7.1.40.0030.00915.92
7.1.30.0030.00715.93
7.1.20.0030.01015.49
7.1.10.0070.00315.83
7.1.00.0020.04619.28
7.0.330.0100.00315.13
7.0.320.0090.00615.52
7.0.310.0000.01115.16
7.0.300.0030.01015.55
7.0.290.0060.01015.58
7.0.280.0070.00715.24
7.0.270.0060.00915.46
7.0.260.0090.00615.53
7.0.250.0060.00615.45
7.0.240.0060.00615.59
7.0.230.0030.00515.52
7.0.220.0030.00615.49
7.0.210.0000.01315.41
7.0.200.0280.01014.97
7.0.190.0070.00315.16
7.0.180.0060.00615.39
7.0.170.0000.01315.49
7.0.160.0030.00615.54
7.0.150.0000.00915.44
7.0.140.0000.01515.49
7.0.130.0130.00315.36
7.0.120.0080.00315.54
7.0.110.0030.00515.29
7.0.100.0160.04117.73
7.0.90.0160.03917.74
7.0.80.0050.02317.67
7.0.70.0050.02317.73
7.0.60.0000.03417.74
7.0.50.0150.02318.02
7.0.40.0030.03516.87
7.0.30.0100.02716.79
7.0.20.0090.04416.68
7.0.10.0080.04316.89
7.0.00.0100.03616.84
5.6.400.0070.00714.34
5.6.390.0030.00614.57
5.6.380.0110.00414.19
5.6.370.0140.00014.48
5.6.360.0110.00614.56
5.6.350.0060.00614.61
5.6.340.0060.01014.29
5.6.330.0040.00714.23
5.6.320.0000.01614.25
5.6.310.0030.00914.42
5.6.300.0060.00614.69
5.6.290.0070.01114.17
5.6.280.0020.03117.82
5.6.270.0000.01114.36
5.6.260.0060.00614.36
5.6.250.0070.04417.61
5.6.240.0100.02317.67
5.6.230.0070.04217.56
5.6.220.0050.04517.60
5.6.210.0020.03117.44
5.6.200.0080.02817.75
5.6.190.0050.03217.73
5.6.180.0080.02317.75
5.6.170.0100.04817.75
5.6.160.0080.04217.80
5.6.150.0070.03917.74
5.6.140.0020.04417.71
5.6.130.0090.04417.81
5.6.120.0080.04317.62
5.6.110.0060.04317.74
5.6.100.0070.04517.65
5.6.90.0100.04717.70
5.6.80.0050.02317.40
5.6.70.0050.03417.38
5.6.60.0050.04117.53
5.6.50.0110.04017.58
5.6.40.0080.02417.45
5.6.30.0050.04017.23
5.6.20.0070.02517.33
5.6.10.0050.04317.27
5.6.00.0060.04317.42
5.5.380.0030.04217.37
5.5.370.0050.02617.43
5.5.360.0100.03017.35
5.5.350.0090.03517.54
5.5.340.0080.03517.86
5.5.330.0030.02717.46
5.5.320.0050.04517.52
5.5.310.0050.04717.58
5.5.300.0030.04817.54
5.5.290.0100.04017.73
5.5.280.0070.04717.72
5.5.270.0060.04517.75
5.5.260.0070.04017.62
5.5.250.0020.04817.50
5.5.240.0000.03817.29
5.5.230.0030.04117.17
5.5.220.0100.03517.31
5.5.210.0070.04417.21
5.5.200.0040.02617.15
5.5.190.0050.04117.31
5.5.180.0070.04017.34
5.5.170.0070.00714.17
5.5.160.0080.03917.26
5.5.150.0040.02617.34
5.5.140.0050.03417.21
5.5.130.0070.03317.07
5.5.120.0050.02517.25
5.5.110.0130.03117.36
5.5.100.0110.03017.09
5.5.90.0030.04617.06
5.5.80.0020.03717.24
5.5.70.0030.04517.21
5.5.60.0000.02717.34
5.5.50.0000.04417.30
5.5.40.0050.04617.24
5.5.30.0050.03817.21
5.5.20.0050.04217.15
5.5.10.0090.02817.25
5.5.00.0070.04216.91
5.4.450.0100.04015.36
5.4.440.0070.04415.27
5.4.430.0050.04515.32
5.4.420.0050.04215.25
5.4.410.0070.03815.28
5.4.400.0080.03815.06
5.4.390.0000.02715.14
5.4.380.0080.04015.04
5.4.370.0050.02415.14
5.4.360.0030.04014.97
5.4.350.0070.03715.02
5.4.340.0100.03615.13
5.4.330.0030.00711.02
5.4.320.0020.03315.03
5.4.310.0060.03815.14
5.4.300.0040.02315.28
5.4.290.0050.04115.10
5.4.280.0030.02315.18
5.4.270.0090.01614.90
5.4.260.0050.03815.25
5.4.250.0050.03715.17
5.4.240.0030.03115.02
5.4.230.0050.04114.91
5.4.220.0070.03615.21
5.4.210.0080.03815.05
5.4.200.0070.01915.16
5.4.190.0090.03714.91
5.4.180.0030.03515.09
5.4.170.0020.04415.12
5.4.160.0100.03115.10
5.4.150.0050.02214.94
5.4.140.0020.04113.72
5.4.130.0040.04013.68
5.4.120.0050.03413.76
5.4.110.0040.02213.75
5.4.100.0070.03713.87
5.4.90.0020.04013.82
5.4.80.0040.04213.68
5.4.70.0030.03013.85
5.4.60.0050.02013.81
5.4.50.0050.03613.70
5.4.40.0020.04613.70
5.4.30.0080.03313.90
5.4.20.0030.02013.86
5.4.10.0050.02113.76
5.4.00.0030.03313.49

preferences:
72.43 ms | 401 KiB | 5 Q