3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo '<html><body>'; echo '<h1>IPv6 Address Summarization Calculator</h1>'; echo 'Instructions:<br>'; echo 'Enter a list of IPv6 addresses or prefixes you\'d like to summarize.<br>'; echo 'You can enter the addresses in compressed or full notation.<br>'; echo '<br>Example:<br>'; echo '2001:CC1E:2AB3:1A3C::<br>'; echo '2001:CC1E:2AB3:1A4D::<br>'; echo 'or<br>'; echo '2606:A700:ABC7:0001::<br>'; echo '2606:A700:ABC7:0002::<br>'; echo '2606:A700:ABC7:0003::<br><br>'; echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">'; echo '<textarea id="ip" name="ip" rows="20" cols="70">'; if (isset($_POST['ip'])) { echo $_POST['ip']; } echo '</textarea>'; echo '<p></p>'; echo '<input type="submit">'; echo '<input type="hidden" name="submitted" id="submitted"></input>'; echo '</form>'; echo '<p></p>'; if(isset($_POST["submitted"]) && $_POST['ip'] != "") { $addr_count = 0; $binary_ip = array(); $search="/^(?>(?>([a-f0-9]{1,4})(?>:(?1)){7}|(?!(?:.*[a-f0-9](?>:|$)){8,})((?1)(?>:(?1)){0,6})?::(?2)?)|(?>(?>(?1)(?>:(?1)){5}:|(?!(?:.*[a-f0-9]:){6,})(?3)?::(?>((?1)(?>:(?1)){0,4}):)?)?(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?4)){3}))$/iD"; $hexarray=array('0' => '0000', '1' => '0001', '2' => '0010', '3' => '0011', '4' => '0100', '5' => '0101', '6' => '0110', '7' => '0111', '8' => '1000', '9' => '1001', 'A' => '1010', 'B' => '1011', 'C' => '1100', 'D' => '1101', 'E' => '1110', 'F' => '1111'); $result=explode(PHP_EOL,trim($_POST['ip'])); foreach ($result as $ip) { if (strpos($ip, '::') !== false) { $part = explode('::', $ip); $part[0] = explode(':', $part[0]); $missing = array(); for ($i = 0; $i < (8 - (count($part[0]) )); $i++) array_push($missing, '0000'); $part = array_merge($part[0], $missing); $newip = ""; $cnt=1; foreach($part as $piece) { if($cnt < 8) { $newip .= $piece.":"; } if($cnt == 8) { $newip .= $piece; } $cnt++; } $ip=$newip; } if(preg_match($search, $ip)) { $addr_count++; $ip = expand($ip); $ip=str_replace(":","",$ip); $fixed_ip_arr=str_split($ip,1); $cnt=0; $fullbinaryip = ""; foreach($fixed_ip_arr as $digit) { $echoip = $hexarray[strtoupper($digit)]; $cnt++; if($cnt % 4 == 0 && $cnt != 32) { $echoip .= ":"; } $fullbinaryip .= $echoip; } array_push($binary_ip, $fullbinaryip); } else { echo "$ip is not in the correct format. If you pasted only a prefix, make sure you end it with ::. I'll ignore it and continue processing.<br>"; } } if($addr_count == 0) { echo "<br>You didn't enter any valid addresses. Please try again.<br>"; exit; } echo "<br>Your addresses in binary form:<br>"; if(count($binary_ip) < 50) { foreach($binary_ip as $value) { echo $value."<br>"; } } else { echo "I don't want to spam you, so I'm not printing all the addresses!<br>"; } $summary = _commonPrefix(str_replace(":","",$binary_ip)); echo "<br>These addresses can be summarized to: <br>"; $final_summary = rtrim(chunk_split(substr(str_replace(":","",$binary_ip['0']),0,$summary), 16, ':'),':'); echo $final_summary."/$summary<br>"; $summary_normal = explode(':', $final_summary); $final_summary_normal = ""; foreach($summary_normal as $block) { $block_smaller = str_split($block, 4); foreach($block_smaller as $tiny) { while (strlen($tiny) < 4) { $tiny .= "0"; } $final_summary_normal .= array_search($tiny, $hexarray); } } echo "You can use this in your router summary statements:<br>"; echo rtrim(chunk_split($final_summary_normal, 4, ':'),':')."/$summary"; } echo '</body>'; echo '</html>'; function expand($ip){ $hex = unpack("H*hex", inet_pton($ip)); $ip = substr(preg_replace("/([A-f0-9]{4})/", "$1:", $hex['hex']), 0, -1); return $ip; } function _commonPrefix($array) { if(count($array) < 2) { if(count($array) == 0) return false; // empty array: undefined prefix else return strlen($array[0]); // 1 element: trivial case } $len = max(array_map('strlen',$array)); // initial upper limit: max length of all strings. $prevval = reset($array); while(($newval = next($array)) !== FALSE) { for($j = 0 ; $j < $len ; $j += 1) if($newval[$j] != $prevval[$j]) $len = $j; $prevval = $newval; } return $len; } ?>

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.0100.01018.18
8.3.50.0110.00821.85
8.3.40.0100.00718.81
8.3.30.0040.01118.85
8.3.20.0080.00018.54
8.3.10.0030.00520.96
8.3.00.0000.00821.95
8.2.180.0150.00616.50
8.2.170.0100.00322.96
8.2.160.0110.00322.08
8.2.150.0030.00524.18
8.2.140.0060.00324.66
8.2.130.0080.00026.16
8.2.120.0040.00421.06
8.2.110.0100.00022.20
8.2.100.0060.00618.03
8.2.90.0070.00317.75
8.2.80.0080.00018.78
8.2.70.0000.00819.75
8.2.60.0040.00417.63
8.2.50.0090.00017.75
8.2.40.0000.00818.41
8.2.30.0000.00821.14
8.2.20.0000.00817.75
8.2.10.0000.00817.70
8.2.00.0040.00417.79
8.1.280.0070.01125.92
8.1.270.0000.00823.99
8.1.260.0080.00026.35
8.1.250.0040.00428.09
8.1.240.0060.00323.79
8.1.230.0110.00019.14
8.1.220.0080.00017.91
8.1.210.0000.00818.77
8.1.200.0090.00017.25
8.1.190.0060.00317.48
8.1.180.0040.00418.10
8.1.170.0030.00618.73
8.1.160.0060.00318.93
8.1.150.0090.00018.59
8.1.140.0000.00717.54
8.1.130.0030.00317.87
8.1.120.0100.00017.56
8.1.110.0050.00317.48
8.1.100.0040.00417.50
8.1.90.0030.00517.52
8.1.80.0030.00317.50
8.1.70.0050.00217.38
8.1.60.0040.00417.46
8.1.50.0040.00417.45
8.1.40.0030.00617.57
8.1.30.0090.00017.65
8.1.20.0050.00317.63
8.1.10.0000.00717.52
8.1.00.0000.00817.47
8.0.300.0000.00818.77
8.0.290.0040.00416.88
8.0.280.0000.00718.44
8.0.270.0000.00717.27
8.0.260.0030.00316.91
8.0.250.0080.00017.04
8.0.240.0080.00017.05
8.0.230.0030.00317.00
8.0.220.0000.00716.90
8.0.210.0040.00416.90
8.0.200.0070.00017.02
8.0.190.0070.00016.91
8.0.180.0000.00716.95
8.0.170.0000.00816.84
8.0.160.0000.00716.98
8.0.150.0040.00416.87
8.0.140.0040.00416.89
8.0.130.0030.00313.43
8.0.120.0040.00416.86
8.0.110.0060.00316.93
8.0.100.0000.00716.80
8.0.90.0040.00417.00
8.0.80.0130.01016.96
8.0.70.0000.00816.86
8.0.60.0050.00216.96
8.0.50.0040.00416.96
8.0.30.0100.01017.20
8.0.20.0110.00717.40
8.0.10.0000.00816.90
8.0.00.0070.01116.92
7.4.330.0000.00516.84
7.4.320.0030.00316.56
7.4.300.0030.00316.67
7.4.290.0000.00716.63
7.4.280.0040.00316.59
7.4.270.0070.00016.54
7.4.260.0030.00313.29
7.4.250.0040.00416.66
7.4.240.0040.00416.66
7.4.230.0040.00416.69
7.4.220.0040.01216.63
7.4.210.0070.00816.62
7.4.200.0050.00216.39
7.4.190.0070.00016.41
7.4.160.0080.00816.48
7.4.150.0000.01817.40
7.4.140.0110.00717.86
7.4.130.0140.00616.62
7.4.120.0080.01016.47
7.4.110.0060.01016.55
7.4.100.0150.00316.61
7.4.90.0140.00316.45
7.4.80.0030.01319.39
7.4.70.0040.01516.60
7.4.60.0080.00816.56
7.4.50.0030.00616.50
7.4.40.0110.00422.77
7.4.30.0150.00316.61
7.4.00.0090.00715.19
7.3.330.0030.00313.42
7.3.320.0000.00513.42
7.3.310.0000.00716.54
7.3.300.0040.00416.52
7.3.290.0170.00416.45
7.3.280.0060.01316.48
7.3.270.0100.00717.40
7.3.260.0120.00818.24
7.3.250.0100.00716.61
7.3.240.0110.00716.50
7.3.230.0120.00616.64
7.3.210.0140.00316.42
7.3.200.0150.00719.39
7.3.190.0110.00716.66
7.3.180.0110.00716.38
7.3.170.0080.00816.55
7.3.160.0100.00616.50
7.3.120.0080.00815.04
7.3.110.0090.01215.02
7.3.100.0090.01015.16
7.3.90.0100.00314.99
7.3.80.0030.00615.08
7.3.70.0040.00714.62
7.3.60.0080.00414.93
7.3.50.0070.00714.84
7.3.40.0100.00014.73
7.3.30.0060.01214.91
7.3.20.0000.01716.63
7.3.10.0090.00516.65
7.3.00.0070.00616.56
7.2.330.0110.00716.61
7.2.320.0100.01316.82
7.2.310.0180.00016.59
7.2.300.0040.01916.80
7.2.290.0080.00816.83
7.2.250.0070.01315.28
7.2.240.0060.01315.41
7.2.230.0110.00415.48
7.2.220.0000.01815.22
7.2.210.0060.00615.45
7.2.200.0050.00515.11
7.2.190.0070.01015.21
7.2.180.0000.01414.94
7.2.170.0040.01215.30
7.2.160.0030.01614.91
7.2.150.0090.00616.91
7.2.140.0000.01017.11
7.2.130.0070.00716.83
7.2.120.0070.00617.01
7.2.110.0020.01216.99
7.2.100.0050.00716.90
7.2.90.0070.00916.95
7.2.80.0070.00816.74
7.2.70.0060.00716.66
7.2.60.0020.01117.05
7.2.50.0070.00716.97
7.2.40.0070.00416.99
7.2.30.0080.00516.95
7.2.20.0030.01016.92
7.2.10.0040.00716.88
7.2.00.0050.01017.78
7.1.330.0030.01215.81
7.1.320.0090.00615.70
7.1.310.0060.00615.83
7.1.300.0040.01215.47
7.1.290.0060.00615.80
7.1.280.0090.00615.77
7.1.270.0140.00415.59
7.1.260.0070.00715.73
7.1.250.0100.00215.49
7.1.240.0090.00915.71
7.1.230.0120.00315.94
7.1.220.0030.01415.74
7.1.210.0030.01015.40
7.1.200.0040.01215.43
7.1.190.0070.00715.49
7.1.180.0040.00415.43
7.1.170.0030.00615.77
7.1.160.0000.01015.44
7.1.150.0070.00315.77
7.1.140.0080.00515.69
7.1.130.0060.00615.49
7.1.120.0060.00915.73
7.1.110.0040.00415.70
7.1.100.0060.00516.77
7.1.90.0060.00715.70
7.1.80.0100.00315.89
7.1.70.0040.00616.47
7.1.60.0120.00717.54
7.1.50.0170.00825.28
7.1.40.0000.01115.55
7.1.30.0030.01015.54
7.1.20.0080.00815.74
7.1.10.0000.01315.88
7.1.00.0020.03519.19
7.0.330.0030.00615.48
7.0.320.0030.01015.26
7.0.310.0090.00615.17
7.0.300.0030.01015.34
7.0.290.0120.00615.27
7.0.280.0030.01015.25
7.0.270.0060.00915.13
7.0.260.0060.00615.23
7.0.250.0040.00815.30
7.0.240.0040.00815.47
7.0.230.0070.00715.18
7.0.220.0030.01315.31
7.0.210.0040.00815.38
7.0.200.0030.00516.11
7.0.190.0070.00315.02
7.0.180.0110.00015.14
7.0.170.0000.01415.38
7.0.160.0040.00415.37
7.0.150.0030.00815.38
7.0.140.0020.04518.68
7.0.130.0060.00615.43
7.0.120.0040.00715.32
7.0.110.0080.00315.44
7.0.100.0120.03317.65
7.0.90.0020.04817.68
7.0.80.0050.04217.68
7.0.70.0070.04517.72
7.0.60.0090.04117.68
7.0.50.0180.02818.04
7.0.40.0050.03216.75
7.0.30.0030.05116.58
7.0.20.0000.05616.69
7.0.10.0080.04316.67
7.0.00.0050.05016.62
5.6.400.0030.01014.69
5.6.390.0030.00914.46
5.6.380.0030.00914.59
5.6.370.0060.00614.56
5.6.360.0070.01014.75
5.6.350.0100.00714.41
5.6.340.0080.00614.31
5.6.330.0090.00614.48
5.6.320.0030.00914.14
5.6.310.0060.00314.63
5.6.300.0040.00814.64
5.6.290.0000.01014.55
5.6.280.0080.03717.88
5.6.270.0100.00614.64
5.6.260.0090.00014.62
5.6.250.0050.04517.64
5.6.240.0090.04217.52
5.6.230.0030.04317.41
5.6.220.0130.03717.72
5.6.210.0060.02817.63
5.6.200.0090.04517.79
5.6.190.0060.05317.65
5.6.180.0060.04617.64
5.6.170.0090.03817.64
5.6.160.0060.04617.81
5.6.150.0080.03917.76
5.6.140.0070.03817.74
5.6.130.0070.02717.79
5.6.120.0060.02617.85
5.6.110.0080.02217.75
5.6.100.0020.04817.75
5.6.90.0080.04517.92
5.6.80.0030.04717.29
5.6.70.0050.03017.41
5.6.60.0060.03617.40
5.6.50.0050.04217.45
5.6.40.0050.03917.54
5.6.30.0080.04117.51
5.6.20.0050.04717.46
5.6.10.0010.04117.43
5.6.00.0080.04417.25
5.5.380.0030.04517.31
5.5.370.0090.03517.46
5.5.360.0080.05117.42
5.5.350.0070.04217.59
5.5.340.0130.03117.67
5.5.330.0030.04617.87
5.5.320.0060.03617.61
5.5.310.0020.02817.69
5.5.300.0060.03117.69
5.5.290.0050.04317.57
5.5.280.0020.03317.57
5.5.270.0070.03717.44
5.5.260.0100.03817.59
5.5.250.0050.03117.45
5.5.240.0030.04617.39
5.5.230.0030.03417.34
5.5.220.0050.04217.19
5.5.210.0080.04017.30
5.5.200.0020.03217.33
5.5.190.0020.05017.40
5.5.180.0030.04017.26
5.5.170.0030.00713.92
5.5.160.0070.04117.35
5.5.150.0070.03217.37
5.5.140.0040.02217.26
5.5.130.0000.04817.44
5.5.120.0000.03417.03
5.5.110.0030.04717.17
5.5.100.0080.03517.21
5.5.90.0070.03917.24
5.5.80.0050.04017.28
5.5.70.0070.03817.19
5.5.60.0050.02917.34
5.5.50.0080.02017.24
5.5.40.0030.02817.29
5.5.30.0080.03017.17
5.5.20.0050.02717.19
5.5.10.0030.02717.28
5.5.00.0050.04617.30
5.4.450.0120.03215.11
5.4.440.0030.05115.31
5.4.430.0050.02315.16
5.4.420.0070.02315.36
5.4.410.0030.04215.13
5.4.400.0100.03715.23
5.4.390.0080.02514.98
5.4.380.0080.03215.06
5.4.370.0050.04014.95
5.4.360.0070.03215.07
5.4.350.0070.03715.07
5.4.340.0080.03514.92
5.4.330.0040.00811.02
5.4.320.0070.03514.98
5.4.310.0060.03614.96
5.4.300.0050.04514.85
5.4.290.0060.03015.12
5.4.280.0050.02114.96
5.4.270.0050.04115.05
5.4.260.0100.03515.09
5.4.250.0050.03514.92
5.4.240.0050.02515.01
5.4.230.0080.03815.24
5.4.220.0000.03515.12
5.4.210.0070.04015.12
5.4.200.0070.03814.78
5.4.190.0080.04015.04
5.4.180.0080.02814.98
5.4.170.0070.03615.07
5.4.160.0080.02515.08
5.4.150.0030.03515.07
5.4.140.0080.02013.81
5.4.130.0030.03813.84
5.4.120.0080.03613.63
5.4.110.0020.03513.86
5.4.100.0050.03813.79
5.4.90.0050.04013.75
5.4.80.0030.03513.81
5.4.70.0030.02813.61
5.4.60.0030.03513.72
5.4.50.0060.03813.82
5.4.40.0080.03313.82
5.4.30.0100.03313.79
5.4.20.0090.03213.89
5.4.10.0070.03413.93
5.4.00.0020.03913.44
5.3.290.0060.04112.61
5.3.280.0050.02312.58
5.3.270.0050.03812.65
5.3.260.0050.02412.59
5.3.250.0110.03912.61
5.3.240.0030.02712.60
5.3.230.0100.03312.55
5.3.220.0030.02312.54
5.3.210.0070.03012.61
5.3.200.0050.04112.65
5.3.190.0050.02512.65
5.3.180.0090.02512.63
5.3.170.0080.02612.69
5.3.160.0020.03712.68
5.3.150.0050.03712.54
5.3.140.0050.04012.56
5.3.130.0070.02712.58
5.3.120.0020.04012.64
5.3.110.0090.03312.61
5.3.100.0100.03712.33
5.3.90.0100.03312.39
5.3.80.0070.03512.27
5.3.70.0060.03612.36
5.3.60.0060.04112.32
5.3.50.0050.03012.22
5.3.40.0050.04112.30
5.3.30.0120.03512.24
5.3.20.0030.03312.14
5.3.10.0070.01912.16
5.3.00.0030.04212.13

preferences:
50.34 ms | 400 KiB | 5 Q