3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Function `parse_yturl()` from <http://stackoverflow.com/a/10524505/624466> /** * Check if the input string is a valid YouTube URL * and try to extract the YouTube Video ID from it. * * @author Stephan Schmitz <eyecatchup@gmail.com> * @param $url string The string that shall be checked. * @return mixed YouTube Video ID, or (boolean) false. */ function parse_yturl($url) { $pattern = '#^(?:https?://|//)?' # Optional URL scheme. Either http, or https, or protocol-relative. . '(?:www\.|m\.)?' # Optional www or m subdomain. . '(?:' # Group host alternatives: . 'youtu\.be/' # Either youtu.be, . '|youtube\.com/' # or youtube.com . '(?:' # Group path alternatives: . 'embed/' # Either /embed/, . '|v/' # or /v/, . '|watch\?v=' # or /watch?v=, . '|watch\?.+&v=' # or /watch?other_param&v= . ')' # End path alternatives. . ')' # End host alternatives. . '([\w-]{11})' # 11 characters (Length of Youtube video ids). . '(?![\w-])#'; # Rejects if overlong id. preg_match($pattern, $url, $matches); return (isset($matches[1])) ? $matches[1] : false; } // Tests for function `parse_yturl()` $testIds = [ 'l8qdouU9cYE', '_PqP1qHhsyM', '3G3_im4RyI8', 'uqU4Mkd-_gU', ]; $testUrls = [ // Without scheme and subdomain (Domain: youtu.be, Path: /) 'youtu.be/%s', // Without scheme, with subdomain (Domain: youtu.be, Path: /) 'www.youtu.be/%s', // With HTTP scheme, without subdomain (Domain: youtu.be, Path: /) 'http://youtu.be/%s', // With HTTP scheme and subdomain (Domain: youtu.be, Path: /) 'http://www.youtu.be/%s', // With HTTPS scheme, without subdomain (Domain: youtu.be, Path: /) 'https://youtu.be/%s', // With HTTPS scheme and subdomain (Domain: youtu.be, Path: /) 'https://www.youtu.be/%s', // Without scheme and subdomain (Domain: youtube.com, Path: /embed) 'youtube.com/embed/%s', 'youtube.com/embed/%s&other_params', // Without scheme, with subdomain (Domain: youtube.com, Path: /embed) 'www.youtube.com/embed/%s', 'www.youtube.com/embed/%s&other_params', // With HTTP scheme, without subdomain (Domain: youtube.com, Path: /embed) 'http://youtube.com/embed/%s', 'http://youtube.com/embed/%s&other_params', // With HTTP scheme and subdomain (Domain: youtube.com, Path: /embed) 'http://www.youtube.com/embed/%s', 'http://www.youtube.com/embed/%s&other_params', // With HTTPS scheme, without subdomain (Domain: youtube.com, Path: /embed) 'https://youtube.com/embed/%s', 'https://youtube.com/embed/%s&other_params', // With HTTPS scheme and subdomain (Domain: youtube.com, Path: /embed) 'https://www.youtube.com/embed/%s', 'https://www.youtube.com/embed/%s&other_params', // Without scheme and subdomain (Domain: youtube.com, Path: /v) 'youtube.com/v/%s', 'youtube.com/v/%s&other_params', // Without scheme, with subdomain (Domain: youtube.com, Path: /v) 'www.youtube.com/v/%s', 'www.youtube.com/v/%s&other_params', // With HTTP scheme, without subdomain (Domain: youtube.com, Path: /v) 'http://youtube.com/v/%s', 'http://youtube.com/v/%s&other_params', // With HTTP scheme and subdomain (Domain: youtube.com, Path: /v) 'http://www.youtube.com/v/%s', 'http://www.youtube.com/v/%s&other_params', // With HTTPS scheme, without subdomain (Domain: youtube.com, Path: /v) 'https://youtube.com/v/%s', 'https://youtube.com/v/%s&other_params', // With HTTPS scheme and subdomain (Domain: youtube.com, Path: /v) 'https://www.youtube.com/v/%s', 'https://www.youtube.com/v/%s&other_params', // Without scheme and subdomain (Domain: youtube.com, Path: /watch) 'youtube.com/watch?v=%s', 'youtube.com/watch?v=%s&other_params', 'youtube.com/watch?other_params&v=%s', 'youtube.com/watch?other_params&v=%s&more_params', // Without scheme, with subdomain (Domain: youtube.com, Path: /watch) 'www.youtube.com/watch?v=%s', 'www.youtube.com/watch?v=%s&other_params', 'www.youtube.com/watch?other_params&v=%s', 'www.youtube.com/watch?other_params&v=%s&more_params', // With HTTP scheme, without subdomain (Domain: youtube.com, Path: /watch) 'http://youtube.com/watch?v=%s', 'http://youtube.com/watch?v=%s&other_params', 'http://youtube.com/watch?other_params&v=%s', 'http://youtube.com/watch?other_params&v=%s&more_params', // With HTTP scheme and subdomain (Domain: youtube.com, Path: /watch) 'http://www.youtube.com/watch?v=%s', 'http://www.youtube.com/watch?v=%s&other_params', 'http://www.youtube.com/watch?other_params&v=%s', 'http://www.youtube.com/watch?other_params&v=%s&more_params', // With HTTPS scheme, without subdomain (Domain: youtube.com, Path: /watch) 'https://youtube.com/watch?v=%s', 'https://youtube.com/watch?v=%s&other_params', 'https://youtube.com/watch?other_params&v=%s', 'https://youtube.com/watch?other_params&v=%s&more_params', // With HTTPS scheme and subdomain (Domain: youtube.com, Path: /watch) 'https://www.youtube.com/watch?v=%s', 'https://www.youtube.com/watch?v=%s&other_params', 'https://www.youtube.com/watch?other_params&v=%s', 'https://www.youtube.com/watch?other_params&v=%s&more_params', ]; $results = []; foreach ($testIds as $id) { $results[$id] = []; foreach ($testUrls as $str) { $testString = sprintf($str, $id); array_push($results[$id], [ 'str' => $testString, 'id' => parse_yturl($testString), ]); } } $matches = 0; $errors = 0; foreach ($results as $key => $val) { $testId = $key; printf('# Testing strings for id "%s"' . PHP_EOL . PHP_EOL, $testId); foreach ($val as $res) { if ($res['id'] !== $testId) { $errors++; $result = 'no match'; } else { $matches++; $result = $res['id']; } printf(' Result: %s, String: %s' . PHP_EOL, $result, $res['str']); } print PHP_EOL; } printf('Done. %d assertation(s), %d error(s)' . PHP_EOL, $matches, $errors);

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.00717.00
8.3.50.0120.00318.30
8.3.40.0060.00919.12
8.3.30.0090.00619.18
8.3.20.0030.00620.45
8.3.10.0080.00022.15
8.3.00.0030.00521.98
8.2.180.0180.00425.92
8.2.170.0110.00719.34
8.2.160.0090.00622.96
8.2.150.0090.00025.66
8.2.140.0050.00324.66
8.2.130.0000.00822.33
8.2.120.0050.00326.16
8.2.110.0130.00320.64
8.2.100.0120.00020.74
8.1.280.0160.00325.92
8.1.270.0080.00023.86
8.1.260.0080.00026.35
8.1.250.0050.00328.09
8.1.240.0070.00418.88
8.1.230.0100.00020.66
7.4.80.0150.01017.94
7.4.70.0110.01216.57
7.4.60.0170.00616.64
7.4.50.0070.01316.63
7.4.40.0150.01016.55
7.4.30.0100.01016.83
7.4.20.0100.01016.43
7.4.10.0090.01416.54
7.4.00.0120.00916.11
7.3.200.0090.01416.61
7.3.190.0200.00316.68
7.3.180.0120.01116.73
7.3.170.0100.01216.59
7.3.160.0130.01016.60
7.3.150.0130.01316.95
7.3.140.0230.00616.60
7.3.130.0160.01216.68
7.3.120.0080.01616.71
7.3.110.0210.01016.65
7.3.100.0150.00715.94
7.3.90.0080.01315.95
7.3.80.0090.01115.95
7.3.70.0120.00815.80
7.3.60.0110.00815.59
7.3.50.0140.00415.52
7.3.40.0140.00715.63
7.3.30.0120.00915.47
7.3.20.0370.01015.89
7.3.10.0170.01215.88
7.3.00.0610.01115.99
7.2.320.0170.00616.99
7.2.310.0100.01316.96
7.2.300.0130.01517.02
7.2.290.0130.01217.01
7.2.280.0170.01116.61
7.2.270.0200.01016.88
7.2.260.0200.00816.88
7.2.250.0140.01716.84
7.2.240.0170.00716.75
7.2.230.0080.01316.17
7.2.220.0090.01216.04
7.2.210.0110.01216.06
7.2.200.0120.00916.22
7.2.190.0110.00815.76
7.2.180.0100.00915.98
7.2.170.0120.01015.82
7.2.160.0090.00915.63
7.2.150.0200.01016.05
7.2.140.0230.00816.08
7.2.130.0490.01016.28
7.2.120.0680.01116.25
7.2.110.0550.00916.12
7.2.100.0510.00916.13
7.2.90.0610.01116.12
7.2.80.0470.00816.09
7.2.70.0520.01116.15
7.2.60.0390.01016.33
7.2.50.0540.00916.22
7.2.40.0530.01016.21
7.2.30.0170.01116.08
7.2.20.0130.01016.23
7.2.10.0140.01216.11
7.2.00.0130.01216.31
7.1.330.0040.02216.07
7.1.320.0140.00415.15
7.1.310.0070.01315.34
7.1.300.0100.00815.44
7.1.290.0150.00615.31
7.1.280.0110.01015.39
7.1.270.0130.00715.11
7.1.260.0190.00815.05
7.1.250.0520.00815.07
7.1.240.0710.00815.02
7.1.230.0440.01315.16
7.1.220.0680.01615.17
7.1.210.0660.00815.11
7.1.200.0430.01015.23
7.1.190.0520.01315.11
7.1.180.0590.01115.03
7.1.170.0510.01315.21
7.1.160.0550.01115.14
7.1.150.0230.00715.05
7.1.140.0490.01415.00
7.1.130.0180.00915.01
7.1.120.0160.01115.15
7.1.110.0190.00915.15
7.1.100.0160.01015.08
7.1.90.0200.01015.19
7.1.80.1710.01015.43
7.1.70.1580.00915.63
7.1.60.1470.01118.54
7.1.50.1710.00818.70
7.1.40.1100.01118.67
7.1.30.1040.01421.40
7.1.20.0940.00921.39
7.1.10.0840.01115.37
7.1.00.0770.01115.44
7.0.330.0130.00714.77
7.0.320.0490.00614.64
7.0.310.0550.00814.72
7.0.300.0520.00614.62
7.0.290.0550.00814.61
7.0.280.0130.01314.68
7.0.270.0130.00914.65
7.0.260.0260.00914.66
7.0.250.0280.01214.90
7.0.240.0180.00614.85
7.0.230.0210.01014.70
7.0.220.0470.01214.71
7.0.210.0420.01114.67
7.0.200.1710.00915.21
7.0.190.1800.00914.82
7.0.180.1230.00914.86
7.0.170.1140.01015.05
7.0.160.1180.01315.01
7.0.150.0650.01014.88
7.0.140.0610.01014.99
7.0.130.0650.01015.06
7.0.120.0680.00914.99
7.0.110.0680.01315.03
7.0.100.0710.01014.98
7.0.90.0720.01314.98
7.0.80.0760.00814.99
7.0.70.0740.00914.92
7.0.60.0700.01214.90
7.0.50.0770.00914.99
7.0.40.0710.01215.09
7.0.30.1150.01115.06
7.0.20.0590.01315.13
7.0.10.0700.01015.01
7.0.00.0610.01415.05
5.6.400.0100.01315.03
5.6.390.0130.01114.93
5.6.380.0130.01115.06
5.6.370.0070.01716.38
5.6.360.0070.02216.39
5.6.350.0060.01816.17
5.6.340.0180.00716.11
5.6.330.0130.01716.03
5.6.320.0110.01516.28
5.6.310.0070.01716.32
5.6.300.0090.02216.23
5.6.290.0120.01516.02
5.6.280.0080.01916.52
5.6.270.0160.01616.15
5.6.260.0090.01716.41
5.6.250.0080.02316.14
5.6.240.0130.01016.07
5.6.230.0180.02316.14
5.6.220.0240.00816.25
5.6.210.0170.01516.14
5.6.200.0190.01516.09
5.6.190.0060.02716.18
5.6.180.0200.01716.07
5.6.170.0110.01816.25
5.6.160.0180.01316.40
5.6.150.0220.00416.27
5.6.140.0120.02416.17
5.6.130.0110.01416.20
5.6.120.0160.01216.27
5.6.110.0230.01116.25
5.6.100.0100.01616.27
5.6.90.0120.01216.05
5.6.80.0080.01615.90
5.6.70.0090.01216.19
5.6.60.0070.01816.17
5.6.50.0230.00616.32
5.6.40.0180.01116.27
5.6.30.0160.01316.07
5.6.20.0250.00316.09
5.6.10.0060.01716.12
5.6.00.0080.01915.90
5.5.380.0210.01916.09
5.5.370.0200.02016.06
5.5.360.0270.01416.02
5.5.350.0180.02116.35
5.5.340.0150.01816.06
5.5.330.0270.01416.12
5.5.320.0270.00616.28
5.5.310.0280.00816.35
5.5.300.0200.01316.43
5.5.290.0120.01516.34
5.5.280.0060.01716.09
5.5.270.0060.01616.20
5.5.260.0070.02316.24
5.5.250.0030.02216.25
5.5.240.0130.01316.15
5.5.230.0200.01315.98
5.5.220.0060.01816.29
5.5.210.0160.01016.06
5.5.200.0080.02216.18
5.5.190.0100.01616.14
5.5.180.0040.01915.99
5.5.170.0240.00916.14
5.5.160.0180.02016.04
5.5.150.0270.00716.34
5.5.140.0220.01516.13
5.5.130.0230.01515.71
5.5.120.0270.01216.03
5.5.110.0240.01315.98
5.5.100.0230.01416.11
5.5.90.0260.01216.12
5.5.80.0150.01515.99
5.5.70.0220.00916.04
5.5.60.0190.01616.05
5.5.50.0220.01116.16
5.5.40.0240.00916.02
5.5.30.0280.00616.11
5.5.20.0200.01415.91
5.5.10.0270.01716.00
5.5.00.0210.01416.23
5.4.450.0130.00813.16
5.4.440.0090.01013.18
5.4.430.0060.01513.04
5.4.420.0090.00913.05
5.4.410.0120.00613.19
5.4.400.0050.01512.96
5.4.390.0120.00913.04
5.4.380.0120.00913.00
5.4.370.0050.01513.09
5.4.360.0170.00312.84
5.4.350.0120.01212.98
5.4.340.0060.01612.88
5.4.330.0190.00612.92
5.4.320.0210.01212.97
5.4.310.0110.01812.92
5.4.300.0230.01312.87
5.4.290.0100.02312.75
5.4.280.0250.00712.72
5.4.270.0190.01112.82
5.4.260.0190.00612.71
5.4.250.0130.01012.69
5.4.240.0180.00712.71
5.4.230.0260.00612.83
5.4.220.0140.01412.71
5.4.210.0180.00912.82
5.4.200.0290.00012.95
5.4.190.0190.01312.96
5.4.180.0220.00712.99
5.4.170.0230.00913.00
5.4.160.0050.01612.80
5.4.150.0200.00412.74
5.4.140.0130.00812.79
5.4.130.0110.01112.75
5.4.120.0150.01513.27
5.4.110.0100.02012.76
5.4.100.0080.01412.86
5.4.90.0180.01012.88
5.4.80.0120.01613.02
5.4.70.0160.01313.02
5.4.60.0200.00712.96
5.4.50.0110.01112.79
5.4.40.0160.00812.80
5.4.30.0200.01412.91
5.4.20.0210.00712.94
5.4.10.0150.00812.74
5.4.00.0090.01412.85
5.3.290.0250.00012.80
5.3.280.0230.00612.79
5.3.270.0120.01212.84
5.3.260.0150.01112.73
5.3.250.0160.00812.76
5.3.240.0180.00812.73
5.3.230.0130.01612.68
5.3.220.0210.00912.66
5.3.210.0180.00912.66
5.3.200.0220.00312.95
5.3.190.0100.01912.78
5.3.180.0180.00712.87
5.3.170.0220.00312.98
5.3.160.0150.01112.83
5.3.150.0200.00412.98
5.3.140.0200.00612.79
5.3.130.0130.01912.80
5.3.120.0150.01012.92
5.3.110.0170.00712.84
5.3.100.0120.01212.84
5.3.90.0120.01212.88
5.3.80.0160.01012.78
5.3.70.0120.01212.86
5.3.60.0230.00012.77
5.3.50.0150.01112.82
5.3.40.0080.01612.84
5.3.30.0230.00912.75
5.3.20.0180.01012.68
5.3.10.0130.01312.48
5.3.00.0140.01412.63
5.2.170.0070.01411.74
5.2.160.0140.00912.09
5.2.150.0190.00611.79
5.2.140.0160.00811.75
5.2.130.0100.01011.75
5.2.120.0120.00911.72
5.2.110.0120.01211.88
5.2.100.0190.00311.75
5.2.90.0120.00811.73
5.2.80.0150.00611.75
5.2.70.0200.00011.97
5.2.60.0090.01311.66
5.2.50.0080.01211.85
5.2.40.0060.01211.75
5.2.30.0160.00511.80
5.2.20.0200.00011.68
5.2.10.0090.01411.52
5.2.00.0110.00811.54
5.1.60.0140.00411.02
5.1.50.0110.00810.76
5.1.40.0110.00511.21
5.1.30.0110.00611.04
5.1.20.0110.00611.00
5.1.10.0050.01110.88
5.1.00.0060.01210.77
5.0.50.0110.00810.11
5.0.40.0070.00810.11
5.0.30.0090.00910.11
5.0.20.0110.00410.11
5.0.10.0110.00510.11
5.0.00.0060.00910.11
4.4.90.0040.00810.11
4.4.80.0100.00210.11
4.4.70.0070.00510.11
4.4.60.0040.00510.11
4.4.50.0040.00610.11
4.4.40.0090.00010.11
4.4.30.0090.00010.11
4.4.20.0070.00410.11
4.4.10.0060.00610.11
4.4.00.0060.00310.11
4.3.110.0000.00910.11
4.3.100.0060.00610.11
4.3.90.0080.00410.11
4.3.80.0060.00310.11
4.3.70.0080.00210.11
4.3.60.0090.00010.11
4.3.50.0090.00210.11
4.3.40.0100.00310.11
4.3.30.0050.00310.11
4.3.20.0100.00010.11
4.3.10.0110.00010.11
4.3.00.0040.00410.11

preferences:
51.36 ms | 401 KiB | 5 Q