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 = true; 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; } } } echo "13"."\n"; return $return; } else { // Uma faixa 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.0110.00716.63
8.3.50.0120.01021.99
8.3.40.0090.00618.87
8.3.30.0110.00318.71
8.3.20.0000.00820.51
8.3.10.0040.00423.65
8.3.00.0040.00419.25
8.2.180.0070.01118.41
8.2.170.0120.00322.96
8.2.160.0070.00721.94
8.2.150.0060.00324.18
8.2.140.0000.00824.66
8.2.130.0070.00026.16
8.2.120.0040.00417.63
8.2.110.0060.00322.08
8.2.100.0070.00718.16
8.2.90.0000.00819.30
8.2.80.0050.00317.97
8.2.70.0080.00017.50
8.2.60.0000.00818.03
8.2.50.0080.00018.07
8.2.40.0000.00719.65
8.2.30.0040.00420.84
8.2.20.0040.00417.77
8.2.10.0000.00718.11
8.2.00.0030.00618.19
8.1.280.0100.01025.92
8.1.270.0060.00323.91
8.1.260.0080.00026.35
8.1.250.0040.00428.09
8.1.240.0040.00422.49
8.1.230.0040.00817.78
8.1.220.0080.00017.90
8.1.210.0100.00018.77
8.1.200.0000.00917.35
8.1.190.0040.00417.35
8.1.180.0000.00918.10
8.1.170.0000.00818.55
8.1.160.0040.00422.19
8.1.150.0020.00519.02
8.1.140.0040.00419.71
8.1.130.0070.00017.75
8.1.120.0050.00317.49
8.1.110.0000.00717.46
8.1.100.0000.00817.48
8.1.90.0050.00317.59
8.1.80.0040.00417.47
8.1.70.0000.00717.46
8.1.60.0040.00417.70
8.1.50.0050.00317.63
8.1.40.0080.00017.63
8.1.30.0080.00017.70
8.1.20.0040.00417.73
8.1.10.0040.00417.61
8.1.00.0080.00017.55
8.0.300.0040.00418.77
8.0.290.0070.00016.88
8.0.280.0000.00718.57
8.0.270.0070.00017.37
8.0.260.0000.00617.25
8.0.250.0070.00017.05
8.0.240.0030.00617.08
8.0.230.0050.00316.97
8.0.220.0050.00317.00
8.0.210.0000.00717.03
8.0.200.0040.00417.11
8.0.190.0040.00416.95
8.0.180.0040.00417.00
8.0.170.0000.00717.01
8.0.160.0030.00517.10
8.0.150.0020.00516.79
8.0.140.0040.00416.91
8.0.130.0000.00613.42
8.0.120.0050.00316.98
8.0.110.0000.00816.92
8.0.100.0000.00816.98
8.0.90.0030.00517.08
8.0.80.0060.00917.00
8.0.70.0040.00416.84
8.0.60.0050.00216.89
8.0.50.0000.00817.02
8.0.30.0100.01017.12
8.0.20.0130.00817.40
8.0.10.0000.00817.14
8.0.00.0090.00916.97
7.4.330.0000.00515.14
7.4.320.0050.00516.67
7.4.300.0000.00616.54
7.4.290.0000.00716.77
7.4.280.0080.00016.46
7.4.270.0050.00316.70
7.4.260.0000.00716.47
7.4.250.0040.00416.47
7.4.240.0000.00716.72
7.4.230.0040.00416.46
7.4.220.0150.00616.64
7.4.210.0050.00916.73
7.4.200.0030.00516.72
7.4.160.0040.01216.70
7.4.150.0120.00617.40
7.4.140.0130.00517.86
7.4.130.0130.00616.77
7.4.120.0110.01016.75
7.4.110.0110.00616.67
7.4.100.0090.00916.63
7.4.90.0120.00416.50
7.4.80.0150.00419.39
7.4.70.0040.01116.69
7.4.60.0070.01016.51
7.4.50.0000.00816.50
7.4.40.0070.01516.75
7.4.30.0090.00916.68
7.4.00.0120.00414.94
7.3.330.0060.00013.29
7.3.320.0030.00313.21
7.3.310.0070.00016.31
7.3.300.0030.00316.43
7.3.290.0000.00716.29
7.3.280.0070.00816.42
7.3.270.0060.01517.40
7.3.260.0150.00316.63
7.3.250.0090.00916.62
7.3.240.0120.00916.56
7.3.230.0120.01216.65
7.3.210.0100.00816.61
7.3.200.0130.00416.82
7.3.190.0130.00316.54
7.3.180.0080.00816.66
7.3.170.0140.00316.76
7.3.160.0030.01316.70
7.2.330.0110.00716.82
7.2.320.0110.00716.87
7.2.310.0100.00616.60
7.2.300.0090.01216.88
7.2.290.0110.01116.79
7.2.60.0070.00716.83
7.2.00.0070.01019.55
7.1.200.0030.01015.73
7.1.70.0000.01117.21
7.1.60.0130.00017.29
7.1.50.0030.01516.99
7.1.00.0030.07722.36
7.0.200.0030.00716.79
7.0.100.0030.05019.99
7.0.90.0070.08019.98
7.0.80.0000.06720.00
7.0.70.0070.07720.04
7.0.60.0130.07720.02
7.0.50.0070.08020.41
7.0.40.0200.06720.04
7.0.30.0100.08019.95
7.0.20.0070.08720.15
7.0.10.0130.07020.17
7.0.00.0130.08020.18
5.6.280.0100.06021.17
5.6.250.0130.06720.65
5.6.240.0100.06320.74
5.6.230.0100.08020.68
5.6.220.0070.08020.66
5.6.210.0030.08020.62
5.6.200.0170.07021.00
5.6.190.0000.09721.02
5.6.180.0070.08721.16
5.6.170.0130.08021.14
5.6.160.0100.08021.10
5.6.150.0130.07321.14
5.6.140.0070.08021.07
5.6.130.0030.05721.10
5.6.120.0100.09021.14
5.6.110.0000.08721.09
5.6.100.0170.07321.10
5.6.90.0070.08321.05
5.6.80.0200.06720.61
5.6.70.0070.06320.41
5.6.60.0130.07720.54
5.6.50.0070.08020.50
5.6.40.0000.08320.34
5.6.30.0070.08020.56
5.6.20.0130.07720.46
5.6.10.0100.04320.40
5.6.00.0030.08020.44
5.5.380.0000.09020.52
5.5.370.0130.07320.39
5.5.360.0030.08320.44
5.5.350.0070.08320.46
5.5.340.0070.07720.96
5.5.330.0200.07320.83
5.5.320.0130.07720.86
5.5.310.0030.07720.89
5.5.300.0030.07320.69
5.5.290.0130.07720.94
5.5.280.0100.08320.93
5.5.270.0130.08020.94
5.5.260.0030.09020.88
5.5.250.0230.06720.75
5.5.240.0030.08320.20
5.5.230.0200.07020.26
5.5.220.0170.07320.36
5.5.210.0030.05020.16
5.5.200.0000.08320.31
5.5.190.0100.07320.21
5.5.180.0130.07320.33
5.5.160.0130.06720.21
5.5.150.0000.08020.31
5.5.140.0170.07720.22
5.5.130.0100.07720.29
5.5.120.0200.06720.18
5.5.110.0070.07720.29
5.5.100.0100.07720.04
5.5.90.0070.04720.16
5.5.80.0070.04720.15
5.5.70.0070.07720.11
5.5.60.0100.07720.19
5.5.50.0000.09320.11
5.5.40.0100.07320.21
5.5.30.0130.06720.15
5.5.20.0000.08720.11
5.5.10.0100.06320.13
5.5.00.0030.08320.16
5.4.450.0030.08319.21
5.4.440.0130.07019.46
5.4.430.0070.07719.37
5.4.420.0100.07319.22
5.4.410.0130.06319.24
5.4.400.0070.07718.97
5.4.390.0070.07319.14
5.4.380.0100.07319.03
5.4.370.0030.07318.86
5.4.360.0230.06719.21
5.4.350.0070.08019.04
5.4.340.0030.05019.14
5.4.320.0130.06719.21
5.4.310.0030.06018.88
5.4.300.0000.07318.88
5.4.290.0070.05019.18
5.4.280.0000.08319.16
5.4.270.0030.08319.02
5.4.260.0000.08019.14
5.4.250.0000.08019.03
5.4.240.0030.08019.21
5.4.230.0070.06018.84
5.4.220.0170.06019.23
5.4.210.0130.06318.92
5.4.200.0100.07319.06
5.4.190.0070.07319.13
5.4.180.0030.07719.15
5.4.170.0170.06718.87
5.4.160.0000.08019.19
5.4.150.0130.05019.16
5.4.140.0000.04316.45
5.4.130.0000.04016.50
5.4.120.0070.07716.50
5.4.110.0000.08016.39
5.4.100.0170.03016.45
5.4.90.0130.05716.53
5.4.80.0130.05316.50
5.4.70.0070.06716.47
5.4.60.0200.06316.54
5.4.50.0030.07716.54
5.4.40.0100.06716.50
5.4.30.0030.07316.41
5.4.20.0070.05716.38
5.4.10.0030.05016.45
5.4.00.0130.07015.95

preferences:
34.79 ms | 401 KiB | 5 Q