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,127.0.0.2-127.0.0.7");

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.00416.75
8.3.50.0170.00522.18
8.3.40.0080.00818.92
8.3.30.0070.00718.89
8.3.20.0070.00020.36
8.3.10.0080.00023.65
8.3.00.0040.00419.25
8.2.180.0210.00018.41
8.2.170.0120.00319.20
8.2.160.0030.01422.24
8.2.150.0110.00024.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0000.00918.00
8.2.110.0100.00019.45
8.2.100.0090.00318.16
8.2.90.0080.00019.33
8.2.80.0030.00517.97
8.2.70.0080.00317.75
8.2.60.0030.00518.18
8.2.50.0000.00818.07
8.2.40.0000.00818.35
8.2.30.0030.00518.36
8.2.20.0040.00417.84
8.2.10.0040.00418.28
8.2.00.0040.00418.22
8.1.280.0140.00325.92
8.1.270.0030.00623.68
8.1.260.0080.00026.35
8.1.250.0000.00828.09
8.1.240.0070.00322.74
8.1.230.0040.00819.27
8.1.220.0000.00818.04
8.1.210.0050.00318.77
8.1.200.0060.00317.47
8.1.190.0080.00017.48
8.1.180.0040.00418.10
8.1.170.0040.00418.84
8.1.160.0030.00519.07
8.1.150.0040.00419.07
8.1.140.0040.00419.75
8.1.130.0050.00217.84
8.1.120.0040.00417.65
8.1.110.0000.00717.64
8.1.100.0040.00417.59
8.1.90.0000.00717.62
8.1.80.0060.00317.61
8.1.70.0000.00717.67
8.1.60.0000.00717.82
8.1.50.0030.00617.70
8.1.40.0060.00317.63
8.1.30.0040.00417.75
8.1.20.0080.00017.80
8.1.10.0050.00317.76
8.1.00.0000.00917.70
8.0.300.0060.00318.84
8.0.290.0000.00917.00
8.0.280.0080.00018.54
8.0.270.0030.00317.43
8.0.260.0030.00517.37
8.0.250.0040.00417.07
8.0.240.0000.01017.18
8.0.230.0080.00017.14
8.0.220.0000.00717.14
8.0.210.0000.00817.14
8.0.200.0000.00717.12
8.0.190.0080.00017.15
8.0.180.0000.00816.98
8.0.170.0030.00516.96
8.0.160.0080.00016.99
8.0.150.0060.00316.99
8.0.140.0000.00817.03
8.0.130.0070.00013.48
8.0.120.0050.00317.07
8.0.110.0050.00217.11
8.0.100.0050.00217.03
8.0.90.0080.00017.09
8.0.80.0070.00717.05
8.0.70.0080.00016.91
8.0.60.0040.00416.93
8.0.50.0040.00417.03
8.0.30.0090.00917.32
8.0.20.0120.00917.40
8.0.10.0050.00317.04
8.0.00.0090.00916.85
7.4.330.0000.00615.14
7.4.320.0040.00416.76
7.4.300.0000.00616.69
7.4.290.0000.00716.78
7.4.280.0040.00416.69
7.4.270.0000.00716.59
7.4.260.0050.00216.83
7.4.250.0000.00816.60
7.4.240.0080.00016.66
7.4.230.0040.00416.58
7.4.220.0110.00916.87
7.4.210.0100.00616.73
7.4.200.0000.00716.89
7.4.160.0080.00816.50
7.4.150.0100.00717.40
7.4.140.0100.00917.86
7.4.130.0150.01116.59
7.4.120.0070.01016.80
7.4.110.0160.00316.69
7.4.100.0210.00316.55
7.4.90.0100.01316.67
7.4.80.0140.00919.39
7.4.70.0070.01016.58
7.4.60.0070.01016.82
7.4.50.0050.00316.54
7.4.40.0060.01816.79
7.4.30.0070.01116.64
7.4.00.0080.00715.09
7.3.330.0030.00313.55
7.3.320.0060.00013.61
7.3.310.0030.00416.49
7.3.300.0000.00716.40
7.3.290.0030.00316.58
7.3.280.0060.01016.58
7.3.270.0130.00717.40
7.3.260.0090.00916.47
7.3.240.0140.00916.63
7.3.230.0130.00616.51
7.3.210.0090.00916.49
7.3.200.0090.01516.86
7.3.190.0090.01216.70
7.3.180.0060.01016.56
7.3.170.0090.01216.82
7.3.160.0030.01416.65
7.3.120.0050.01315.06
7.3.110.0020.01615.08
7.3.100.0100.00614.90
7.3.90.0030.01015.05
7.3.80.0070.00514.93
7.3.70.0050.00615.14
7.3.60.0030.01014.91
7.3.50.0050.01015.06
7.3.40.0030.00914.86
7.3.30.0060.00514.71
7.3.20.0020.00916.80
7.3.10.0040.01016.72
7.3.00.0090.00516.80
7.2.330.0130.00316.95
7.2.320.0070.01316.54
7.2.310.0040.01416.87
7.2.300.0120.00616.93
7.2.290.0060.01816.84
7.2.250.0120.00815.02
7.2.240.0080.00515.35
7.2.230.0060.00815.16
7.2.220.0070.00615.37
7.2.210.0030.01015.23
7.2.200.0100.00315.17
7.2.190.0020.01415.24
7.2.180.0050.01015.13
7.2.170.0050.00915.26
7.2.160.0110.00315.00
7.2.150.0040.01117.02
7.2.140.0000.01316.98
7.2.130.0080.00416.65
7.2.120.0000.01516.84
7.2.110.0080.00417.07
7.2.100.0030.01216.71
7.2.90.0070.00317.05
7.2.80.0100.00617.16
7.2.70.0000.01517.09
7.2.60.0030.01216.95
7.2.50.0040.00817.02
7.2.40.0090.00917.12
7.2.30.0030.00917.06
7.2.20.0060.01016.86
7.2.10.0040.01216.80
7.2.00.0050.00818.25
7.1.330.0050.01115.99
7.1.320.0020.01015.71
7.1.310.0030.01015.92
7.1.300.0050.00715.75
7.1.290.0070.00615.88
7.1.280.0040.00915.92
7.1.270.0080.00315.90
7.1.260.0040.01215.80
7.1.250.0030.01015.85
7.1.200.0090.00315.99
7.1.100.0000.01518.19
7.1.70.0040.00417.40
7.1.60.0090.00419.43
7.1.50.0030.01917.09
7.1.00.0070.07322.48
7.0.200.0840.00614.88
7.0.100.0100.07720.09
7.0.90.0100.07720.04
7.0.80.0070.08020.05
7.0.70.0070.08320.18
7.0.60.0070.08720.19
7.0.50.0170.07020.38
7.0.40.0130.07020.08
7.0.30.0030.06720.14
7.0.20.0100.07719.98
7.0.10.0130.05720.10
7.0.00.0130.06320.13
5.6.280.0070.06321.02
5.6.250.0100.08320.72
5.6.240.0170.07320.61
5.6.230.0170.05320.63
5.6.220.0200.07320.68
5.6.210.0100.08020.75
5.6.200.0070.09021.14
5.6.190.0130.07721.05
5.6.180.0070.07021.11
5.6.170.0170.07321.09
5.6.160.0030.07321.04
5.6.150.0070.07721.06
5.6.140.0100.06021.15
5.6.130.0230.07021.18
5.6.120.0130.07321.06
5.6.110.0030.08721.02
5.6.100.0100.08321.21
5.6.90.0100.08021.21
5.6.80.0100.07720.61
5.6.70.0170.06320.51
5.6.60.0030.08020.50
5.6.50.0070.08720.59
5.6.40.0100.07720.50
5.6.30.0230.06320.34
5.6.20.0100.07320.36
5.6.10.0070.04720.58
5.6.00.0100.07720.52
5.5.380.0070.05020.49
5.5.370.0070.05720.44
5.5.360.0200.07020.48
5.5.350.0100.08020.46
5.5.340.0070.08320.90
5.5.330.0130.07320.90
5.5.320.0070.08321.00
5.5.310.0030.06720.96
5.5.300.0130.06320.86
5.5.290.0130.07320.82
5.5.280.0100.07720.98
5.5.270.0100.08020.89
5.5.260.0270.06021.01
5.5.250.0070.08020.80
5.5.240.0100.05020.29
5.5.230.0030.08720.11
5.5.220.0100.07720.24
5.5.210.0100.07720.31
5.5.200.0070.06320.18
5.5.190.0130.07320.08
5.5.180.0100.08020.27
5.5.160.0130.07020.21
5.5.150.0070.07720.30
5.5.140.0070.08020.33
5.5.130.0030.08020.21
5.5.120.0070.07720.21
5.5.110.0100.07320.16
5.5.100.0070.05020.17
5.5.90.0100.07020.25
5.5.80.0100.07320.18
5.5.70.0130.07320.25
5.5.60.0030.08720.15
5.5.50.0070.07320.18
5.5.40.0100.08320.21
5.5.30.0030.05720.18
5.5.20.0130.07720.19
5.5.10.0030.08020.21
5.5.00.0100.07720.18
5.4.450.0070.05719.48
5.4.440.0000.08719.53
5.4.430.0170.06719.57
5.4.420.0030.09019.50
5.4.410.0030.06319.51
5.4.400.0030.08319.30
5.4.390.0070.07318.96
5.4.380.0100.07319.28
5.4.370.0070.07719.10
5.4.360.0100.07018.96
5.4.350.0070.08019.02
5.4.340.0170.06719.13
5.4.320.0070.04719.07
5.4.310.0000.05019.30
5.4.300.0130.07019.32
5.4.290.0000.08719.09
5.4.280.0070.08018.91
5.4.270.0130.03719.11
5.4.260.0070.07319.30
5.4.250.0070.07319.27
5.4.240.0030.08319.10
5.4.230.0200.05718.89
5.4.220.0000.07719.27
5.4.210.0130.07019.09
5.4.200.0070.05719.27
5.4.190.0100.06719.10
5.4.180.0100.07719.14
5.4.170.0070.07719.10
5.4.160.0070.08018.95
5.4.150.0100.06719.09
5.4.140.0070.07316.59
5.4.130.0070.07316.54
5.4.120.0100.06716.61
5.4.110.0030.06316.63
5.4.100.0130.06716.55
5.4.90.0200.06316.55
5.4.80.0100.07016.46
5.4.70.0070.07716.60
5.4.60.0000.07716.59
5.4.50.0030.07716.36
5.4.40.0100.07016.42
5.4.30.0070.07316.43
5.4.20.0100.07016.39
5.4.10.0170.03716.58
5.4.00.0100.07015.98

preferences:
55.57 ms | 401 KiB | 5 Q