3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class UrlScraper { private static $encoding; private static $array; private static function call($name) { return array(__CLASS__, $name); } private static function checkEmpty($dir) { return $dir !== '.' && $dir !== ''; } private static function htmlDecode($html) { return html_entity_decode($html, ENT_QUOTES, self::$encoding); } private static function mergeRecursive($item) { if (!self::checkEmpty($item)) { self::$array[] = $item; } } private static function parseUrl($url, $is_base = false) { if ( strpos($url, 'javascript:') === 0 or false === $p = parse_url($url) or $is_base && !isset($p['host']) ) { throw new InvalidArgumentException('Invalid URL'); } $p['scheme'] = isset($p['scheme']) ? $p['scheme'] . '://' : 'http://'; $p['port'] = isset($p['port']) ? ':' . $p['port'] : ''; $p['path'] = isset($p['path']) ? $p['path'] : ''; $q['head'] = isset($p['host']) ? $p['scheme'] . $p['host'] . $p['port'] : ''; $q['query'] = isset($p['query']) ? '?' . $p['query'] : ''; $q['fragment'] = isset($p['fragment']) ? '#' . $p['fragment'] : ''; $q['dirs'] = explode('/', $p['path']); $q['is_abs'] = $p['path'] !== '' && $q['dirs'][0] === ''; $q['is_dir'] = end($q['dirs']) === ''; $q['dirs'] = array_values(array_filter($q['dirs'], self::call('checkEmpty'))); return $q; } public static function parseLinks($html, $base_url = null, $encoding = 'UTF-8') { $regex = '@<a[^>]*?(?<!\.)href="([^"]*+)"[^>]*+>(.*?)</a>@si'; if (!preg_match_all($regex, $html, $matches, PREG_SET_ORDER)) { return array(); } if ($base_url !== null) { $p = self::parseUrl($base_url, true);; if (!$p['is_dir']) { array_pop($p['dirs']); } } $array = array(); foreach ($matches as $match) { list(, $set['href'], $set['label']) = $match; try { $q = self::parseUrl($set['href']); if ($base_url === null) { if ($q['head'] === '' && $q['query'] === '' && !$q['dirs'] && !$q['is_abs']) { continue; } } else { if ($q['head'] === '') { $tmp = $q['is_abs'] ? array() : $p['dirs']; foreach ($q['dirs'] as $dir) { if ($dir === '..') { array_pop($tmp); } } self::$array = array(); call_user_func( 'array_walk_recursive', array($p['head'], $tmp, $q['query'], $q['fragment']), self::call('mergeRecursive') ); $set['href'] = implode('/', self::$array); } else { $tmp = array_filter($q['dirs'], self::call('checkEmpty')); } if ($p['dirs'] === $tmp && $p['query'] === $q['query']) { continue; } } $set['label'] = ( '' === $text = trim(strip_tags($set['label'])) and preg_match_all('@(?<!\.)alt="([^"]++)"@', $set['label'], $matches) ) ? implode(' - ', $matches[1]) : $text ; self::$encoding = $encoding; $set = array_map(self::call('htmlDecode'), $set); $array[serialize($set)] = $set; } catch (Exception $e) { } } return array_values($array); } } $html = <<<EOD <a href="jump.php">画像A[TEXT]<img src="image_a.png" alt="画像A[ALT]" /></a> <a href="jump.php"><img src="image_a.png" alt="画像B[ALT]" /></a> EOD; $base_url = 'http://example.com/foo/bar/'; $base_url = null; var_dump($base_url, UrlScraper::parseLinks($html, $base_url));

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.01118.68
8.3.50.0130.00621.33
8.3.40.0110.00719.04
8.3.30.0040.01120.29
8.3.20.0080.00020.16
8.3.10.0040.00422.04
8.3.00.0030.00622.51
8.2.180.0110.01116.88
8.2.170.0070.01422.96
8.2.160.0040.01122.38
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0080.00026.16
8.2.120.0040.00421.13
8.2.110.0030.00622.21
8.2.100.0000.01218.16
8.2.90.0030.00619.17
8.2.80.0040.00419.37
8.2.70.0000.01317.84
8.2.60.0080.00018.05
8.2.50.0000.00918.07
8.2.40.0050.00620.00
8.2.30.0000.00719.53
8.2.20.0030.00617.95
8.2.10.0050.00317.97
8.2.00.0040.00418.03
8.1.280.0190.01125.92
8.1.270.0040.00423.99
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0070.01024.01
8.1.230.0070.00418.94
8.1.220.0000.00817.80
8.1.210.0030.00618.77
8.1.200.0070.00317.60
8.1.190.0040.00417.65
8.1.180.0030.00618.10
8.1.170.0000.00818.68
8.1.160.0000.00718.96
8.1.150.0040.00418.78
8.1.140.0000.00817.78
8.1.130.0000.00717.93
8.1.120.0030.00517.67
8.1.110.0000.00917.70
8.1.100.0030.00517.67
8.1.90.0060.00317.67
8.1.80.0000.00717.70
8.1.70.0030.00317.59
8.1.60.0040.00417.70
8.1.50.0050.00317.78
8.1.40.0030.00517.79
8.1.30.0060.00317.75
8.1.20.0000.00817.79
8.1.10.0000.00817.70
8.1.00.0030.00617.84
8.0.300.0040.00418.77
8.0.290.0040.00417.30
8.0.280.0070.00018.55
8.0.270.0000.00817.47
8.0.260.0080.00017.05
8.0.250.0000.00717.26
8.0.240.0030.00817.11
8.0.230.0040.00417.23
8.0.220.0050.00217.07
8.0.210.0000.00817.09
8.0.200.0000.00717.22
8.0.190.0000.00817.25
8.0.180.0000.00717.15
8.0.170.0080.00017.10
8.0.160.0040.00417.12
8.0.150.0030.00517.14
8.0.140.0040.00417.19
8.0.130.0000.00613.56
8.0.120.0030.00517.12
8.0.110.0040.00417.07
8.0.100.0040.00417.04
8.0.90.0050.00317.29
8.0.80.0120.00317.09
8.0.70.0040.00417.16
8.0.60.0040.00417.07
8.0.50.0030.00517.06
8.0.30.0100.01017.20
8.0.20.0100.01217.40
8.0.10.0000.00817.30
8.0.00.0080.01116.91
7.4.330.0000.00615.00
7.4.320.0050.00216.78
7.4.300.0060.00016.69
7.4.290.0000.00716.89
7.4.280.0040.00816.86
7.4.270.0050.00516.77
7.4.260.0050.00013.52
7.4.250.0000.00816.89
7.4.240.0040.00416.76
7.4.230.0000.00816.75
7.4.220.0100.01016.87
7.4.210.0090.00916.83
7.4.200.0020.00516.65
7.4.190.0000.00716.87
7.4.160.0180.00716.79
7.4.150.0160.00617.40
7.4.140.0100.01217.86
7.4.130.0080.00816.78
7.4.120.0090.00916.88
7.4.110.0140.00316.76
7.4.100.0090.00916.72
7.4.90.0070.01416.79
7.4.80.0070.01619.39
7.4.70.0130.00816.71
7.4.60.0030.01916.84
7.4.50.0000.00916.78
7.4.40.0030.01022.77
7.4.30.0000.01816.81
7.4.00.0100.00715.26
7.3.330.0000.00513.63
7.3.320.0030.00313.50
7.3.310.0050.00316.67
7.3.300.0000.00716.60
7.3.290.0030.01016.72
7.3.280.0070.01016.68
7.3.270.0070.01317.40
7.3.260.0130.00616.90
7.3.250.0090.01416.76
7.3.240.0170.00316.59
7.3.230.0090.00916.77
7.3.210.0130.00716.59
7.3.200.0080.01019.39
7.3.190.0060.01216.98
7.3.180.0130.00316.69
7.3.170.0130.00316.64
7.3.160.0070.01016.61
7.3.120.0100.00714.89
7.3.110.0060.00614.98
7.3.100.0060.00915.43
7.3.90.0110.00615.08
7.3.80.0060.00614.88
7.3.70.0070.00315.30
7.3.60.0030.01314.88
7.3.50.0100.00715.15
7.3.40.0000.01314.82
7.3.30.0090.00315.16
7.3.20.0040.01416.71
7.3.10.0060.00916.90
7.3.00.0000.01116.81
7.2.330.0110.00816.93
7.2.320.0120.01216.95
7.2.310.0120.00616.72
7.2.300.0120.00616.82
7.2.290.0080.00817.04
7.2.250.0090.00915.19
7.2.240.0060.01615.45
7.2.230.0000.01115.34
7.2.220.0060.00915.28
7.2.210.0040.00815.43
7.2.200.0000.00815.19
7.2.190.0000.01015.10
7.2.180.0070.01015.43
7.2.170.0030.01315.14
7.2.60.0110.00717.23
7.2.00.0040.01219.49
7.1.330.0120.00316.24
7.1.320.0040.00815.77
7.1.310.0040.01116.02
7.1.300.0060.00615.98
7.1.290.0040.01115.95
7.1.280.0080.00416.01
7.1.270.0030.01115.76
7.1.260.0030.01015.84
7.1.200.0100.00315.84
7.1.100.0090.00618.18
7.1.70.0050.00317.29
7.1.60.0130.01319.32
7.1.50.0090.00317.25
7.1.00.0030.07322.59
7.0.200.0170.00716.82
7.0.140.0030.07722.09
7.0.100.0070.04320.08
7.0.90.0170.07719.98
7.0.80.0130.07319.92
7.0.70.0270.08020.05
7.0.60.0030.08319.93
7.0.50.0170.07320.32
7.0.40.0100.04720.13
7.0.30.0070.08719.95
7.0.20.0170.07020.05
7.0.10.0070.07319.95
7.0.00.0130.07020.08
5.6.280.0070.07021.15
5.6.250.0070.08320.57
5.6.240.0130.04720.79
5.6.230.0100.08720.52
5.6.220.0030.04020.54
5.6.210.0100.07320.72
5.6.200.0100.09021.12
5.6.190.0100.08321.03
5.6.180.0170.07721.07
5.6.170.0030.09020.99
5.6.160.0100.07021.09
5.6.150.0170.04321.14
5.6.140.0070.06721.10
5.6.130.0000.08021.02
5.6.120.0070.07321.09
5.6.110.0070.07721.11
5.6.100.0070.08721.05
5.6.90.0070.07721.02
5.6.80.0070.07020.42
5.6.70.0100.08020.35
5.6.60.0000.08720.51
5.6.50.0000.05320.49
5.6.40.0030.08320.44
5.6.30.0100.07720.43
5.6.20.0100.07720.41
5.6.10.0200.05320.40
5.6.00.0030.05320.41
5.5.380.0100.07320.40
5.5.370.0030.07720.42
5.5.360.0170.06320.38
5.5.350.0100.06720.46
5.5.340.0130.08020.84
5.5.330.0100.06320.91
5.5.320.0030.07320.87
5.5.310.0100.07720.75
5.5.300.0170.08720.79
5.5.290.0130.07020.92
5.5.280.0100.07320.85
5.5.270.0070.07720.88
5.5.260.0100.05020.95
5.5.250.0070.06320.45
5.5.240.0170.06720.27
5.5.230.0100.04320.32
5.5.220.0070.08020.27
5.5.210.0070.05720.30
5.5.200.0130.07320.16
5.5.190.0000.05720.21
5.5.180.0030.04320.30
5.5.160.0030.08020.30
5.5.150.0030.08720.17
5.5.140.0100.07020.29
5.5.130.0130.04320.25
5.5.120.0170.06320.16
5.5.110.0070.08320.25
5.5.100.0070.04719.99
5.5.90.0100.05320.09
5.5.80.0130.07320.14
5.5.70.0130.07320.19
5.5.60.0200.03720.13
5.5.50.0130.06320.09
5.5.40.0070.04320.09
5.5.30.0070.05320.05
5.5.20.0100.03720.17
5.5.10.0170.02720.13
5.5.00.0030.04020.15
5.4.450.0000.05719.36
5.4.440.0130.06019.45
5.4.430.0070.08019.20
5.4.420.0070.08019.37
5.4.410.0030.05319.34
5.4.400.0130.06018.88
5.4.390.0130.07319.13
5.4.380.0070.04319.02
5.4.370.0070.07718.95
5.4.360.0070.04719.04
5.4.350.0100.07719.04
5.4.340.0100.07718.95
5.4.320.0030.06318.85
5.4.310.0000.08318.85
5.4.300.0000.09019.18
5.4.290.0130.06719.12
5.4.280.0070.07719.25
5.4.270.0070.04718.90
5.4.260.0100.08019.09
5.4.250.0000.07319.13
5.4.240.0130.06719.13
5.4.230.0130.05719.22
5.4.220.0130.05719.20
5.4.210.0130.04319.13
5.4.200.0100.06719.14
5.4.190.0070.03719.17
5.4.180.0070.03718.84
5.4.170.0070.03719.11
5.4.160.0000.04719.00
5.4.150.0030.03719.07
5.4.140.0100.03016.49
5.4.130.0100.03016.50
5.4.120.0100.03016.46
5.4.110.0070.03016.39
5.4.100.0070.02716.42
5.4.90.0070.03316.46
5.4.80.0000.07316.37
5.4.70.0030.07716.55
5.4.60.0030.06316.28
5.4.50.0000.03316.50
5.4.40.0000.04716.34
5.4.30.0130.02716.42
5.4.20.0070.04716.46
5.4.10.0030.03716.35
5.4.00.0000.04715.96
5.3.290.0000.09014.82
5.3.280.0030.06714.58
5.3.270.0030.04714.73
5.3.260.0000.05014.59
5.3.250.0030.04314.72
5.3.240.0030.03314.71
5.3.230.0100.03714.76
5.3.220.0000.04014.73
5.3.210.0030.04314.54
5.3.200.0100.02714.63
5.3.190.0000.05714.69
5.3.180.0000.07714.68
5.3.170.0000.05014.55
5.3.160.0000.08014.64
5.3.150.0000.08014.73
5.3.140.0030.03714.60
5.3.130.0070.04014.61
5.3.120.0070.03014.65
5.3.110.0030.04014.66
5.3.100.0000.04014.09
5.3.90.0000.04014.00
5.3.80.0070.02713.96
5.3.70.0130.02713.97
5.3.60.0100.02314.21
5.3.50.0070.03313.93
5.3.40.0000.04314.02
5.3.30.0000.04313.98
5.3.20.0070.03013.72
5.3.10.0070.04013.68
5.3.00.0070.03313.71

preferences:
48.19 ms | 401 KiB | 5 Q