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.9");

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.0120.00316.75
8.3.50.0050.01621.99
8.3.40.0140.00718.84
8.3.30.0070.00718.44
8.3.20.0030.00620.51
8.3.10.0080.00023.53
8.3.00.0050.00319.38
8.2.180.0090.00618.04
8.2.170.0110.00722.96
8.2.160.0170.00022.26
8.2.150.0070.00324.18
8.2.140.0070.00024.66
8.2.130.0050.00226.16
8.2.120.0060.00317.50
8.2.110.0080.00322.29
8.2.100.0080.00418.04
8.2.90.0080.00019.30
8.2.80.0000.00917.97
8.2.70.0050.00317.63
8.2.60.0060.00318.05
8.2.50.0000.00818.07
8.2.40.0000.00819.41
8.2.30.0070.00020.85
8.2.20.0000.00817.85
8.2.10.0050.00318.25
8.2.00.0040.00418.15
8.1.280.0120.00625.92
8.1.270.0030.00623.85
8.1.260.0050.00326.35
8.1.250.0090.00028.09
8.1.240.0040.00422.55
8.1.230.0080.00417.79
8.1.220.0040.00417.91
8.1.210.0030.00918.77
8.1.200.0070.00317.47
8.1.190.0090.00017.35
8.1.180.0030.00618.10
8.1.170.0040.00418.71
8.1.160.0040.00422.14
8.1.150.0080.00019.04
8.1.140.0080.00019.55
8.1.130.0040.00417.93
8.1.120.0030.00517.59
8.1.110.0040.00417.62
8.1.100.0050.00317.47
8.1.90.0040.00417.61
8.1.80.0040.00417.62
8.1.70.0020.00517.49
8.1.60.0000.00817.70
8.1.50.0030.00517.70
8.1.40.0000.00817.70
8.1.30.0000.00817.73
8.1.20.0040.00417.77
8.1.10.0040.00417.66
8.1.00.0060.00317.56
8.0.300.0060.00318.77
8.0.290.0040.00416.75
8.0.280.0030.00318.56
8.0.270.0050.00317.44
8.0.260.0030.00517.37
8.0.250.0040.00417.08
8.0.240.0000.00817.14
8.0.230.0050.00317.04
8.0.220.0040.00416.98
8.0.210.0000.00716.98
8.0.200.0030.00317.05
8.0.190.0000.00916.96
8.0.180.0000.00817.07
8.0.170.0080.00017.05
8.0.160.0040.00417.06
8.0.150.0000.00716.88
8.0.140.0000.00716.86
8.0.130.0000.00713.41
8.0.120.0040.00416.96
8.0.110.0030.00517.01
8.0.100.0080.00016.94
8.0.90.0040.00416.90
8.0.80.0040.01117.05
8.0.70.0000.00717.00
8.0.60.0000.00716.96
8.0.50.0080.00016.86
8.0.30.0090.00817.38
8.0.20.0090.01017.43
8.0.10.0080.00017.02
8.0.00.0100.00816.90
7.4.330.0000.00515.09
7.4.320.0040.00416.77
7.4.300.0060.00016.64
7.4.290.0030.00316.75
7.4.280.0030.00616.56
7.4.270.0040.00316.62
7.4.260.0070.00016.55
7.4.250.0040.00416.56
7.4.240.0020.00516.75
7.4.230.0070.00016.82
7.4.220.0110.00916.64
7.4.210.0080.01016.67
7.4.200.0040.00416.67
7.4.160.0000.01516.46
7.4.150.0090.00917.40
7.4.140.0110.00717.86
7.4.130.0100.01516.61
7.4.120.0050.01416.53
7.4.110.0120.00616.75
7.4.100.0140.00316.45
7.4.90.0000.02316.57
7.4.80.0100.00819.39
7.4.70.0030.01316.64
7.4.60.0100.00716.61
7.4.50.0030.00516.63
7.4.40.0090.00916.53
7.4.30.0120.00616.48
7.4.00.0000.01115.13
7.3.330.0000.00613.39
7.3.320.0060.00013.24
7.3.310.0000.00816.42
7.3.300.0000.00716.29
7.3.290.0070.00016.35
7.3.280.0090.01016.44
7.3.270.0070.01017.40
7.3.260.0120.00616.59
7.3.240.0080.01016.48
7.3.230.0150.00316.58
7.3.210.0100.01016.61
7.3.200.0090.01216.68
7.3.190.0140.00716.49
7.3.180.0070.01116.65
7.3.170.0110.01116.71
7.3.160.0120.00616.38
7.2.330.0090.00916.97
7.2.320.0100.01416.55
7.2.310.0040.01616.84
7.2.300.0090.00916.61
7.2.290.0060.01616.59
7.2.60.0070.00716.63
7.2.00.0030.00918.86
7.1.200.0070.00315.74
7.1.100.0000.00818.11
7.1.70.0000.00717.19
7.1.60.0070.00719.43
7.1.50.0040.00817.14
7.1.00.0100.07022.48
7.0.200.2520.00714.71
7.0.100.0200.06720.10
7.0.90.0070.07320.07
7.0.80.0070.08320.02
7.0.70.0100.07320.02
7.0.60.0030.05020.07
7.0.50.0030.08720.36
7.0.40.0100.08320.14
7.0.30.0070.05720.10
7.0.20.0100.06720.09
7.0.10.0130.08020.07
7.0.00.0100.07319.95
5.6.280.0070.05320.88
5.6.250.0100.07320.86
5.6.240.0000.08720.60
5.6.230.0070.05320.65
5.6.220.0100.08320.67
5.6.210.0030.05320.67
5.6.200.0070.08721.14
5.6.190.0100.08721.11
5.6.180.0130.04721.16
5.6.170.0070.07321.07
5.6.160.0100.08021.11
5.6.150.0030.08021.10
5.6.140.0130.04321.16
5.6.130.0030.07321.07
5.6.120.0070.04721.22
5.6.110.0170.05321.18
5.6.100.0100.07721.06
5.6.90.0200.07321.11
5.6.80.0070.08020.52
5.6.70.0030.06720.38
5.6.60.0070.07320.46
5.6.50.0070.03720.52
5.6.40.0070.06020.34
5.6.30.0130.07320.44
5.6.20.0100.08020.43
5.6.10.0030.08020.45
5.6.00.0130.04020.38
5.5.380.0030.08320.55
5.5.370.0070.08320.50
5.5.360.0130.04720.55
5.5.350.0070.08020.50
5.5.340.0130.06720.93
5.5.330.0070.04720.85
5.5.320.0070.08020.86
5.5.310.0100.04320.96
5.5.300.0000.08720.93
5.5.290.0030.08020.94
5.5.280.0070.08020.69
5.5.270.0030.08720.88
5.5.260.0130.07320.82
5.5.250.0000.04020.70
5.5.240.0030.03720.26
5.5.230.0100.08020.32
5.5.220.0100.07320.29
5.5.210.0130.05720.36
5.5.200.0030.07320.33
5.5.190.0200.06020.29
5.5.180.0070.05720.23
5.5.160.0070.07720.01
5.5.150.0000.08320.00
5.5.140.0100.08020.28
5.5.130.0170.05720.31
5.5.120.0200.04720.18
5.5.110.0030.06320.29
5.5.100.0070.06320.17
5.5.90.0070.06720.05
5.5.80.0170.07020.14
5.5.70.0070.06720.17
5.5.60.0030.04720.11
5.5.50.0200.06320.01
5.5.40.0130.04720.14
5.5.30.0030.07320.15
5.5.20.0030.06320.12
5.5.10.0070.04720.06
5.5.00.0170.06720.11
5.4.450.0030.05019.38
5.4.440.0100.06719.17
5.4.430.0100.05019.44
5.4.420.0100.08719.46
5.4.410.0030.07019.35
5.4.400.0100.06719.05
5.4.390.0100.07019.02
5.4.380.0100.06019.03
5.4.370.0070.04318.95
5.4.360.0030.03719.16
5.4.350.0130.07318.85
5.4.340.0170.03319.05
5.4.320.0100.07319.18
5.4.310.0030.08019.14
5.4.300.0100.07019.23
5.4.290.0100.07019.07
5.4.280.0070.07719.03
5.4.270.0030.08019.12
5.4.260.0070.03719.09
5.4.250.0030.04019.09
5.4.240.0170.06719.08
5.4.230.0000.08019.04
5.4.220.0070.04019.09
5.4.210.0100.06719.20
5.4.200.0070.07318.84
5.4.190.0030.04719.22
5.4.180.0100.05719.04
5.4.170.0030.04019.03
5.4.160.0030.07318.86
5.4.150.0070.04719.12
5.4.140.0000.07716.43
5.4.130.0070.06316.46
5.4.120.0000.04016.38
5.4.110.0130.06316.32
5.4.100.0130.06016.49
5.4.90.0130.06016.55
5.4.80.0030.07016.48
5.4.70.0070.04316.55
5.4.60.0070.06016.50
5.4.50.0100.07016.52
5.4.40.0030.05016.40
5.4.30.0070.07316.45
5.4.20.0030.04316.45
5.4.10.0030.08016.34
5.4.00.0070.03715.91

preferences:
59.98 ms | 401 KiB | 5 Q