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; 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.0070.01416.75
8.3.50.0040.01818.12
8.3.40.0120.00318.73
8.3.30.0160.00018.84
8.3.20.0000.00820.45
8.3.10.0080.00023.53
8.3.00.0000.00819.26
8.2.180.0090.00918.16
8.2.170.0070.01022.96
8.2.160.0070.01122.26
8.2.150.0110.00024.18
8.2.140.0030.00524.66
8.2.130.0080.00026.16
8.2.120.0040.00417.75
8.2.110.0060.00321.10
8.2.100.0080.00417.91
8.2.90.0040.00419.22
8.2.80.0080.00017.97
8.2.70.0080.00017.63
8.2.60.0000.00918.05
8.2.50.0030.00518.07
8.2.40.0040.00419.57
8.2.30.0000.00720.74
8.2.20.0030.00617.73
8.2.10.0040.00418.15
8.2.00.0040.00418.23
8.1.280.0110.00725.92
8.1.270.0080.00023.97
8.1.260.0000.00726.35
8.1.250.0040.00428.09
8.1.240.0100.00019.32
8.1.230.0000.01220.97
8.1.220.0040.00417.79
8.1.210.0090.00018.77
8.1.200.0060.00317.35
8.1.190.0040.00417.25
8.1.180.0050.00318.10
8.1.170.0000.00818.66
8.1.160.0030.00522.18
8.1.150.0000.00819.05
8.1.140.0040.00419.71
8.1.130.0070.00017.72
8.1.120.0070.00017.59
8.1.110.0040.00417.57
8.1.100.0050.00317.55
8.1.90.0020.00517.56
8.1.80.0050.00317.48
8.1.70.0000.00717.45
8.1.60.0000.00817.68
8.1.50.0040.00417.70
8.1.40.0030.00517.63
8.1.30.0030.00617.64
8.1.20.0040.00417.63
8.1.10.0000.00717.52
8.1.00.0000.00917.60
8.0.300.0020.00518.77
8.0.290.0080.00016.88
8.0.280.0050.00318.57
8.0.270.0030.00317.28
8.0.260.0000.00717.29
8.0.250.0080.00017.09
8.0.240.0040.00417.07
8.0.230.0030.00317.01
8.0.220.0040.00417.03
8.0.210.0000.00717.07
8.0.200.0000.00716.93
8.0.190.0040.00416.98
8.0.180.0090.00017.04
8.0.170.0050.00316.92
8.0.160.0000.00817.09
8.0.150.0040.00417.02
8.0.140.0040.00416.85
8.0.130.0030.00313.37
8.0.120.0040.00417.00
8.0.110.0030.00517.06
8.0.100.0040.00417.07
8.0.90.0000.00817.04
8.0.80.0040.01216.96
8.0.70.0070.00016.88
8.0.60.0040.00416.82
8.0.50.0000.00816.88
8.0.30.0050.01217.09
8.0.20.0110.00817.40
8.0.10.0040.00417.07
8.0.00.0120.00516.99
7.4.330.0060.00015.08
7.4.320.0040.00416.67
7.4.300.0000.00716.53
7.4.290.0000.00716.54
7.4.280.0040.00416.60
7.4.270.0030.00316.61
7.4.260.0070.00016.71
7.4.250.0050.00216.67
7.4.240.0020.00516.69
7.4.230.0040.00416.75
7.4.220.0060.01216.75
7.4.210.0060.00916.66
7.4.200.0040.00416.61
7.4.160.0070.01016.61
7.4.150.0040.01417.40
7.4.140.0110.00917.86
7.4.130.0150.00316.70
7.4.120.0110.01016.74
7.4.110.0000.01716.52
7.4.100.0110.00616.60
7.4.90.0140.00316.57
7.4.80.0160.00019.39
7.4.70.0070.01016.66
7.4.60.0100.00616.53
7.4.50.0000.00816.46
7.4.40.0110.01116.71
7.4.30.0070.01016.66
7.4.10.0030.01714.89
7.4.00.0070.00915.26
7.3.330.0030.00313.36
7.3.320.0030.00313.41
7.3.310.0030.00316.52
7.3.300.0030.00316.46
7.3.290.0000.00716.42
7.3.280.0090.00716.39
7.3.270.0100.01017.40
7.3.260.0000.01816.68
7.3.250.0090.01116.54
7.3.240.0120.00816.44
7.3.230.0100.01016.53
7.3.210.0100.01016.59
7.3.200.0130.01016.39
7.3.190.0090.00916.39
7.3.180.0070.01016.70
7.3.170.0090.00616.75
7.3.160.0110.00516.69
7.3.130.0040.01114.89
7.3.120.0090.00914.79
7.3.110.0030.01315.14
7.3.100.0070.00714.70
7.3.90.0030.01014.98
7.3.80.0070.00315.07
7.3.70.0070.00714.83
7.3.60.0040.01115.02
7.3.50.0030.00615.12
7.3.40.0030.01015.01
7.3.30.0070.00715.07
7.3.20.0040.01116.84
7.3.10.0080.00816.83
7.3.00.0040.01116.52
7.2.330.0070.01116.96
7.2.320.0070.01316.79
7.2.310.0110.00616.87
7.2.300.0120.00616.85
7.2.290.0090.00916.85
7.2.260.0030.01715.07
7.2.250.0030.01714.97
7.2.240.0090.00615.38
7.2.230.0090.00615.29
7.2.220.0090.00615.29
7.2.210.0030.00715.21
7.2.200.0030.01214.88
7.2.190.0060.00915.02
7.2.180.0070.01115.20
7.2.170.0120.00314.98
7.2.160.0040.00715.08
7.2.150.0030.01216.61
7.2.140.0040.01216.66
7.2.130.0080.00816.96
7.2.120.0000.01216.77
7.2.110.0110.00416.93
7.2.100.0090.00616.73
7.2.90.0000.01316.81
7.2.80.0040.00716.85
7.2.70.0060.00917.07
7.2.60.0070.00717.00
7.2.50.0070.00417.02
7.2.40.0030.01017.06
7.2.30.0070.01017.06
7.2.20.0070.00717.09
7.2.10.0060.00917.05
7.2.00.0090.00317.99
7.1.330.0030.00915.88
7.1.320.0040.00815.89
7.1.310.0040.00715.96
7.1.300.0070.00315.61
7.1.290.0060.00615.55
7.1.280.0080.00415.66
7.1.270.0040.00815.57
7.1.260.0000.01416.02
7.1.250.0040.01215.77
7.1.240.0120.00315.58
7.1.230.0060.01015.96
7.1.220.0060.01015.99
7.1.210.0030.00715.76
7.1.200.0050.00915.64
7.1.190.0040.01115.70
7.1.180.0030.00915.77
7.1.170.0000.01515.71
7.1.160.0070.01015.82
7.1.150.0060.00615.82
7.1.140.0060.00915.93
7.1.130.0060.00915.94
7.1.120.0000.01615.91
7.1.110.0100.00315.65
7.1.100.0060.00617.00
7.1.90.0030.01415.94
7.1.80.0000.01115.89
7.1.70.0020.00916.52
7.1.60.0080.01317.66
7.1.50.0050.01216.56
7.1.40.0030.00915.69
7.1.30.0000.01115.61
7.1.20.0000.01115.69
7.1.10.0030.01015.85
7.1.00.0050.04219.07
7.0.330.0000.01515.17
7.0.320.0070.01015.43
7.0.310.0090.00615.46
7.0.300.0030.00915.40
7.0.290.0030.00715.45
7.0.280.0030.01015.34
7.0.270.0030.00615.38
7.0.260.0040.00715.46
7.0.250.0070.00715.52
7.0.240.0060.00915.31
7.0.230.0120.00615.29
7.0.220.0060.01015.33
7.0.210.0060.00915.54
7.0.200.0470.01115.05
7.0.190.0070.00715.32
7.0.180.0040.00715.22
7.0.170.0030.01415.66
7.0.160.0040.01115.55
7.0.150.0000.01315.11
7.0.140.0000.01515.54
7.0.130.0060.00615.56
7.0.120.0110.00415.34
7.0.110.0030.00615.42
7.0.100.0200.03817.81
7.0.90.0190.04017.76
7.0.80.0070.04217.60
7.0.70.0200.01817.71
7.0.60.0130.02617.70
7.0.50.0020.02618.02
7.0.40.0030.03316.78
7.0.30.0070.02216.74
7.0.20.0050.02516.86
7.0.10.0070.02816.67
7.0.00.0020.03916.89
5.6.400.0000.01414.38
5.6.390.0120.00614.49
5.6.380.0080.00414.22
5.6.370.0030.01014.41
5.6.360.0060.01214.48
5.6.350.0070.01014.57
5.6.340.0070.00714.38
5.6.330.0000.01114.38
5.6.320.0000.00914.31
5.6.310.0080.00814.60
5.6.300.0070.00714.41
5.6.290.0000.01014.34
5.6.280.0050.01817.61
5.6.270.0070.01014.35
5.6.260.0030.00714.30
5.6.250.0050.04517.63
5.6.240.0080.03817.58
5.6.230.0120.04017.46
5.6.220.0100.04517.51
5.6.210.0030.04517.58
5.6.200.0030.02817.77
5.6.190.0030.02617.77
5.6.180.0020.02517.69
5.6.170.0030.02517.63
5.6.160.0030.04517.65
5.6.150.0050.02217.91
5.6.140.0020.02717.87
5.6.130.0030.04317.76
5.6.120.0030.02517.81
5.6.110.0020.03017.65
5.6.100.0050.02617.69
5.6.90.0060.03817.72
5.6.80.0080.02817.47
5.6.70.0000.03217.39
5.6.60.0050.02717.46
5.6.50.0030.02417.32
5.6.40.0070.02217.38
5.6.30.0020.02717.46
5.6.20.0020.02517.38
5.6.10.0050.02317.32
5.6.00.0040.02617.26
5.5.380.0080.02817.36
5.5.370.0070.04017.42
5.5.360.0120.03217.40
5.5.350.0070.04517.38
5.5.340.0050.02317.53
5.5.330.0060.02417.67
5.5.320.0060.02317.76
5.5.310.0060.01817.63
5.5.300.0120.03917.54
5.5.290.0060.02517.57
5.5.280.0060.02517.70
5.5.270.0030.03217.51
5.5.260.0050.03317.41
5.5.250.0080.02217.46
5.5.240.0060.02117.40
5.5.230.0050.02717.22
5.5.220.0050.02517.36
5.5.210.0050.02217.16
5.5.200.0050.02517.13
5.5.190.0030.02317.27
5.5.180.0050.04017.38
5.5.170.0100.00614.11
5.5.160.0050.02517.15
5.5.150.0070.02517.32
5.5.140.0060.02317.36
5.5.130.0030.02517.15
5.5.120.0030.02017.25
5.5.110.0020.02417.24
5.5.100.0080.02017.13
5.5.90.0050.01817.21
5.5.80.0080.03217.06
5.5.70.0050.03217.22
5.5.60.0030.02117.28
5.5.50.0050.03717.19
5.5.40.0050.03017.16
5.5.30.0050.03717.15
5.5.20.0110.03817.11
5.5.10.0070.03517.34
5.5.00.0050.04216.95
5.4.450.0020.02615.02
5.4.440.0080.02415.12
5.4.430.0070.02015.29
5.4.420.0050.02315.21
5.4.410.0040.02915.17
5.4.400.0060.01815.00
5.4.390.0060.02315.09
5.4.380.0020.02415.05
5.4.370.0020.03314.93
5.4.360.0050.02214.93
5.4.350.0060.02114.98
5.4.340.0050.02214.94
5.4.330.0110.00011.11
5.4.320.0050.02515.01
5.4.310.0050.01815.12
5.4.300.0050.02115.06
5.4.290.0050.02615.12
5.4.280.0070.02214.95
5.4.270.0050.02015.10
5.4.260.0070.02015.22
5.4.250.0000.02415.16
5.4.240.0070.01815.17
5.4.230.0050.01814.87
5.4.220.0090.03515.19
5.4.210.0050.04214.93
5.4.200.0030.02814.96
5.4.190.0070.04114.85
5.4.180.0060.02414.98
5.4.170.0050.02814.93
5.4.160.0040.03215.22
5.4.150.0090.04115.02
5.4.140.0040.03813.59
5.4.130.0030.04413.73
5.4.120.0070.03013.78
5.4.110.0020.02913.55
5.4.100.0070.03713.78
5.4.90.0100.03213.85
5.4.80.0100.03513.74
5.4.70.0090.01813.76
5.4.60.0030.03613.63
5.4.50.0020.02413.71
5.4.40.0070.03413.78
5.4.30.0020.03813.66
5.4.20.0090.03813.83
5.4.10.0030.04313.56
5.4.00.0050.04213.38

preferences:
48.21 ms | 400 KiB | 5 Q