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 != $range){ 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.0040.01816.75
8.3.50.0070.01117.78
8.3.40.0120.00918.72
8.3.30.0080.00618.84
8.3.20.0070.00020.34
8.3.10.0080.00023.64
8.3.00.0040.00419.38
8.2.180.0070.01118.40
8.2.170.0140.00722.96
8.2.160.0100.00722.08
8.2.150.0040.00724.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0030.00617.63
8.2.110.0060.00322.16
8.2.100.0030.00917.93
8.2.90.0030.00519.17
8.2.80.0080.00017.97
8.2.70.0000.00817.75
8.2.60.0050.00317.80
8.2.50.0000.00818.07
8.2.40.0000.00919.59
8.2.30.0040.00420.73
8.2.20.0030.00617.75
8.2.10.0030.00518.16
8.2.00.0040.00418.11
8.1.280.0100.00725.92
8.1.270.0050.00323.96
8.1.260.0080.00026.35
8.1.250.0070.00028.09
8.1.240.0030.00722.60
8.1.230.0090.00317.77
8.1.220.0000.00817.78
8.1.210.0110.00018.77
8.1.200.0040.00417.48
8.1.190.0040.00417.36
8.1.180.0040.00418.10
8.1.170.0030.00520.43
8.1.160.0000.00722.05
8.1.150.0040.00418.97
8.1.140.0030.00519.69
8.1.130.0040.00417.95
8.1.120.0030.00517.60
8.1.110.0040.00417.52
8.1.100.0000.00717.52
8.1.90.0000.00717.59
8.1.80.0040.00417.45
8.1.70.0030.00317.58
8.1.60.0040.00417.64
8.1.50.0040.00417.53
8.1.40.0050.00317.66
8.1.30.0060.00317.68
8.1.20.0040.00417.78
8.1.10.0000.00817.61
8.1.00.0060.00317.39
8.0.300.0030.00618.77
8.0.290.0040.00416.88
8.0.280.0030.00518.56
8.0.270.0080.00017.34
8.0.260.0050.00317.38
8.0.250.0000.00716.92
8.0.240.0060.00316.99
8.0.230.0000.00717.11
8.0.220.0070.00017.04
8.0.210.0000.00816.99
8.0.200.0030.00317.11
8.0.190.0000.00817.11
8.0.180.0000.00816.98
8.0.170.0000.00817.06
8.0.160.0000.00717.00
8.0.150.0070.00017.00
8.0.140.0040.00416.86
8.0.130.0060.00013.42
8.0.120.0000.00816.98
8.0.110.0040.00416.92
8.0.100.0040.00417.12
8.0.90.0070.00016.97
8.0.80.0060.00917.06
8.0.70.0000.00717.00
8.0.60.0000.00816.91
8.0.50.0000.00817.05
8.0.30.0090.01417.04
8.0.20.0160.00817.40
8.0.10.0000.00816.95
8.0.00.0090.00916.83
7.4.330.0030.00315.08
7.4.320.0070.00016.75
7.4.300.0000.00616.53
7.4.290.0080.00016.75
7.4.280.0000.00716.62
7.4.270.0000.00716.53
7.4.260.0070.00016.58
7.4.250.0050.00216.68
7.4.240.0000.00716.63
7.4.230.0000.00716.74
7.4.220.0120.01516.58
7.4.210.0050.00916.73
7.4.200.0030.00516.60
7.4.160.0100.00716.50
7.4.150.0030.02017.40
7.4.140.0110.00817.86
7.4.130.0070.01016.64
7.4.120.0090.01116.55
7.4.110.0140.00316.78
7.4.100.0070.01316.70
7.4.90.0170.00316.59
7.4.80.0080.00819.39
7.4.70.0100.00716.77
7.4.60.0110.01116.76
7.4.50.0040.00416.52
7.4.40.0090.01216.43
7.4.30.0060.01216.56
7.4.00.0030.01514.98
7.3.330.0060.00013.42
7.3.320.0050.00013.37
7.3.310.0030.00316.31
7.3.300.0050.00216.38
7.3.290.0050.00216.37
7.3.280.0070.00916.43
7.3.270.0110.00817.40
7.3.260.0180.00616.52
7.3.250.0100.01016.55
7.3.240.0070.01216.50
7.3.230.0200.00316.39
7.3.210.0190.00316.68
7.3.200.0090.00916.36
7.3.190.0120.00416.41
7.3.180.0110.00616.36
7.3.170.0100.00616.72
7.3.160.0170.00016.52
7.2.330.0060.01216.79
7.2.320.0180.00616.77
7.2.310.0060.01116.59
7.2.300.0090.00816.79
7.2.290.0120.00916.68
7.2.60.0040.00416.53
7.2.00.0000.01219.12
7.1.200.0080.00815.59
7.1.100.0040.01118.46
7.1.70.0030.00517.24
7.1.60.0100.01619.43
7.1.50.0030.00716.65
7.1.00.0100.07022.31
7.0.200.0840.00415.08
7.0.100.0030.08320.05
7.0.90.0100.06720.13
7.0.80.0230.06319.99
7.0.70.0270.07720.00
7.0.60.0270.08020.06
7.0.50.0170.06320.45
7.0.40.0070.06320.15
7.0.30.0170.05320.00
7.0.20.0030.08320.06
7.0.10.0170.07720.13
7.0.00.0030.05020.09
5.6.250.0130.07320.86
5.6.240.0130.08020.65
5.6.230.0070.08320.63
5.6.220.0200.07320.72
5.6.210.0130.07020.66
5.6.200.0030.06321.18
5.6.190.0100.05021.09
5.6.180.0130.05721.14
5.6.170.0070.04721.12
5.6.160.0130.07321.12
5.6.150.0070.08321.11
5.6.140.0100.06721.06
5.6.130.0070.08721.06
5.6.120.0130.06721.07
5.6.110.0130.08020.99
5.6.100.0130.06721.11
5.6.90.0100.07021.04
5.6.80.0030.05020.52
5.6.70.0070.08020.48
5.6.60.0070.08020.48
5.6.50.0030.08320.39
5.6.40.0070.05320.37
5.6.30.0070.07320.48
5.6.20.0130.07720.41
5.6.10.0130.07720.43
5.6.00.0070.07020.56
5.5.380.0100.07320.43
5.5.370.0070.08320.51
5.5.360.0130.08020.61
5.5.350.0030.05020.38
5.5.340.0100.08020.91
5.5.330.0070.07720.88
5.5.320.0070.08020.93
5.5.310.0130.07020.96
5.5.300.0130.06320.88
5.5.290.0070.06020.82
5.5.280.0030.08720.83
5.5.270.0070.07020.95
5.5.260.0130.08020.91
5.5.250.0070.08320.79
5.5.240.0100.06320.32
5.5.230.0100.07320.23
5.5.220.0070.07720.21
5.5.210.0070.08020.31
5.5.200.0030.05020.14
5.5.190.0130.07720.24
5.5.180.0100.07020.32
5.5.160.0030.08320.18
5.5.150.0070.07720.32
5.5.140.0070.07720.13
5.5.130.0070.04720.31
5.5.120.0070.06020.22
5.5.110.0070.07720.23
5.5.100.0100.04019.97
5.5.90.0130.07320.03
5.5.80.0030.07720.07
5.5.70.0070.08020.15
5.5.60.0000.05319.99
5.5.50.0070.05320.11
5.5.40.0000.06320.18
5.5.30.0130.07320.06
5.5.20.0000.05019.98
5.5.10.0070.08720.06
5.5.00.0100.07320.07
5.4.450.0100.05719.36
5.4.440.0100.04319.36
5.4.430.0070.07019.36
5.4.420.0030.04719.46
5.4.410.0070.07719.23
5.4.400.0030.08319.04
5.4.390.0130.05018.90
5.4.380.0100.06018.91
5.4.370.0070.08019.18
5.4.360.0000.05019.23
5.4.350.0000.04319.14
5.4.340.0200.06719.04
5.4.320.0070.05018.95
5.4.310.0100.04019.04
5.4.300.0030.07719.04
5.4.290.0130.06718.85
5.4.280.0070.07019.03
5.4.270.0030.04318.90
5.4.260.0070.05318.95
5.4.250.0070.04319.06
5.4.240.0070.07719.16
5.4.230.0130.05719.12
5.4.220.0130.06318.87
5.4.210.0100.06018.94
5.4.200.0030.07719.12
5.4.190.0000.04719.02
5.4.180.0000.04719.20
5.4.170.0000.06019.11
5.4.160.0100.04019.19
5.4.150.0030.07719.21
5.4.140.0070.05716.50
5.4.130.0070.05716.42
5.4.120.0070.07716.34
5.4.110.0130.06316.39
5.4.100.0100.05316.52
5.4.90.0030.04316.40
5.4.80.0030.07016.42
5.4.70.0070.07716.45
5.4.60.0070.06716.46
5.4.50.0030.07016.36
5.4.40.0100.07316.54
5.4.30.0000.07716.37
5.4.20.0030.06316.36
5.4.10.0000.08016.39
5.4.00.0100.06015.70

preferences:
37.14 ms | 400 KiB | 5 Q