3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Parses an RGBA string and returns and array with each color * @param string $str The RGBA string, ex: "rgba(66, 66, 66, 1)" * @return array Returns an array with each r, g, b and a value or false if an invalid string is passed in. */ function parseRGBA($str){ //match the rgba string and get it's part if(preg_match('/rgba\( *([\d\.-]+), *([\d\.-]+), *([\d\.-]+), *([\d\.-]+) *\)/i', $str, $m)){ $out = array( 'r'=>intval($m[1]), //get the red 'g'=>intval($m[2]), //get the green 'b'=>intval($m[3]), //get the blue 'a'=>round(floatval($m[4]) * 255), //get the alpha and scale to 0-255 ); //clamp each value between 0 and 255 array_walk($out, function(&$v){ $v = min(255, max(0, $v)); }); return $out; } return false; } echo '<pre>'; echo "Normal value: "; print_r(parseRGBA("rgba(66, 66, 66, 1)")); echo "Red > 255: "; print_r(parseRGBA("rgba(660, 66, 66, 1)")); echo "Green < 0: "; print_r(parseRGBA("rgba(66, -66, 66, 1)")); echo "Alpha float (normal): "; print_r(parseRGBA("rgba(66, 66, 66, 0.6)")); echo "Alpha overflow: "; print_r(parseRGBA("rgba(66, 66, 66, 10)"));

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.5.10.0070.01020.23
8.5.00.0100.01120.26
8.4.160.0130.00723.99
8.4.150.0020.00114.05
8.4.140.0100.01117.93
8.4.130.0100.01117.86
8.4.120.0070.00220.79
8.4.110.0120.00818.98
8.4.100.0110.00718.02
8.4.90.0110.00920.52
8.4.80.0120.00919.07
8.4.70.0060.00220.74
8.4.60.0100.00718.46
8.4.50.0070.00720.59
8.4.40.0060.01324.15
8.4.30.0030.01622.57
8.4.20.0070.01418.09
8.4.10.0000.00919.64
8.3.280.0130.00818.52
8.3.270.0130.00616.58
8.3.260.0060.00516.95
8.3.250.0150.00419.05
8.3.240.0030.00516.86
8.3.230.0140.00616.89
8.3.220.0120.00619.14
8.3.210.0100.01016.80
8.3.200.0040.00516.88
8.3.190.0060.00416.99
8.3.180.0110.00718.82
8.3.170.0110.00719.07
8.3.160.0140.00616.84
8.3.150.0070.01017.32
8.3.140.0060.01220.92
8.3.130.0150.00018.57
8.3.120.0060.00318.99
8.3.110.0060.00320.94
8.3.100.0080.00016.96
8.3.90.0000.00818.56
8.3.80.0000.00919.36
8.3.70.0060.00916.63
8.3.60.0100.01018.43
8.3.50.0160.00522.89
8.3.40.0140.00419.09
8.3.30.0120.00318.96
8.3.20.0040.00421.82
8.3.10.0070.00323.33
8.3.00.0000.00818.16
8.2.290.0110.00917.05
8.2.280.0130.01018.29
8.2.270.0040.00416.92
8.2.260.0060.00317.40
8.2.250.0000.01016.96
8.2.240.0060.01219.33
8.2.230.0030.00622.58
8.2.220.0130.00324.06
8.2.210.0000.00726.77
8.2.200.0030.00616.75
8.2.190.0040.01116.75
8.2.180.0060.01216.88
8.2.170.0080.00818.98
8.2.160.0070.00722.96
8.2.150.0000.00825.66
8.2.140.0030.00524.66
8.2.130.0040.00426.16
8.2.120.0060.00321.32
8.2.110.0060.01221.20
8.2.100.0080.00417.97
8.2.90.0000.00918.16
8.2.80.0000.00819.23
8.2.70.0000.00917.88
8.2.60.0040.00417.75
8.2.50.0030.00617.88
8.2.40.0030.00618.13
8.2.30.0000.00718.25
8.2.20.0070.00018.09
8.2.10.0000.00718.18
8.2.00.0050.00318.30
8.1.330.0090.00922.28
8.1.320.0120.00817.90
8.1.310.0140.00316.81
8.1.300.0040.00418.28
8.1.290.0090.00018.88
8.1.280.0080.00825.92
8.1.270.0050.00324.66
8.1.260.0050.00326.35
8.1.250.0050.00328.09
8.1.240.0070.00319.26
8.1.230.0110.00020.95
8.1.220.0030.00617.79
8.1.210.0000.00919.05
8.1.200.0000.00817.60
8.1.190.0030.00717.48
8.1.180.0050.00318.10
8.1.170.0090.00017.62
8.1.160.0000.00718.95
8.1.150.0040.00419.00
8.1.140.0000.00719.64
8.1.130.0000.00717.68
8.1.120.0040.00417.59
8.1.110.0030.00517.73
8.1.100.0040.00317.58
8.1.90.0000.00817.70
8.1.80.0000.00717.76
8.1.70.0000.00717.61
8.1.60.0030.00617.84
8.1.50.0040.00417.71
8.1.40.0000.00917.78
8.1.30.0090.00017.73
8.1.20.0030.00517.86
8.1.10.0030.00517.82
8.1.00.0060.00317.79
8.0.300.0000.00820.08
8.0.290.0000.00917.13
8.0.280.0070.00018.42
8.0.270.0000.00717.09
8.0.260.0030.00317.29
8.0.250.0000.00717.13
8.0.240.0070.00017.06
8.0.230.0060.00317.11
8.0.220.0070.00016.92
8.0.210.0030.00316.93
8.0.200.0000.00817.05
8.0.190.0040.00417.19
8.0.180.0020.00517.18
8.0.170.0080.00017.16
8.0.160.0040.00417.02
8.0.150.0000.00817.09
8.0.140.0040.00417.04
8.0.130.0000.00613.57
8.0.120.0050.00317.14
8.0.110.0050.00317.15
8.0.100.0000.00817.13
8.0.90.0090.00017.19
8.0.80.0030.01417.06
8.0.70.0050.00317.00
8.0.60.0000.00717.15
8.0.50.0030.00617.18
8.0.30.0040.01317.49
8.0.20.0110.00917.45
8.0.10.0040.00417.21
8.0.00.0140.00516.95
7.4.330.0050.00015.11
7.4.320.0070.00016.77
7.4.300.0030.00316.88
7.4.290.0030.00316.78
7.4.280.0060.00316.88
7.4.270.0070.00016.88
7.4.260.0070.00016.78
7.4.250.0040.00416.76
7.4.240.0000.00716.79
7.4.230.0030.00316.69
7.4.220.0140.00816.74
7.4.210.0050.01616.87
7.4.200.0070.00016.68
7.4.160.0060.01016.86
7.4.150.0150.00417.40
7.4.140.0090.00917.86
7.4.130.0080.01816.70
7.4.120.0110.00816.82
7.4.110.0150.00416.88
7.4.100.0080.00816.52
7.4.90.0140.01016.82
7.4.80.0060.01119.39
7.4.70.0150.00316.83
7.4.60.0100.00716.73
7.4.50.0100.00716.80
7.4.40.0060.01116.83
7.4.30.0070.01016.78
7.4.10.0100.00715.36
7.4.00.0090.00615.29
7.3.330.0030.00313.50
7.3.320.0000.00513.55
7.3.310.0040.00416.45
7.3.300.0030.00316.46
7.3.290.0080.00816.38
7.3.280.0100.00816.49
7.3.270.0150.00417.40
7.3.260.0150.00916.58
7.3.240.0100.00816.85
7.3.230.0040.01216.70
7.3.210.0150.00316.82
7.3.200.0180.00716.73
7.3.190.0110.00616.50
7.3.180.0110.00716.47
7.3.170.0090.00916.80
7.3.160.0100.00616.52
7.3.130.0090.00914.93
7.3.120.0050.01314.90
7.3.110.0070.01014.89
7.3.100.0080.00815.08
7.3.90.0050.00715.09
7.3.80.0070.00415.05
7.3.70.0060.00914.84
7.3.60.0070.00714.92
7.3.50.0050.00614.96
7.3.40.0060.00914.80
7.3.30.0030.01214.85
7.3.20.0040.01216.83
7.3.10.0090.00316.85
7.3.00.0050.00816.79
7.2.330.0140.00716.96
7.2.320.0030.01617.05
7.2.310.0140.00316.81
7.2.300.0040.01417.10
7.2.290.0110.00716.84
7.2.260.0070.01315.48
7.2.250.0050.01415.33
7.2.240.0050.01215.26
7.2.230.0110.00515.27
7.2.220.0040.01015.38
7.2.210.0040.00915.33
7.2.200.0060.01015.30
7.2.190.0070.00815.12
7.2.180.0050.00815.45
7.2.170.0060.01015.17
7.2.160.0100.00615.27
7.2.150.0030.00916.86
7.2.140.0100.00317.11
7.2.130.0030.01617.18
7.2.120.0120.00617.13
7.2.110.0050.01116.09
7.2.100.0070.00916.11
7.2.90.0110.00316.10
7.2.80.0110.00815.95
7.2.70.0550.00915.57
7.2.60.0450.00716.16
7.2.50.0650.00715.72
7.2.40.0440.00815.97
7.2.30.0140.00915.82
7.2.20.0150.00715.84
7.2.10.0280.01015.92
7.2.00.0090.00716.85
7.1.330.0090.00615.87
7.1.320.0100.00315.89
7.1.310.0050.00816.10
7.1.300.0050.00716.06
7.1.290.0030.00716.06
7.1.280.0090.00515.96
7.1.270.0070.00716.07
7.1.260.0060.00415.95
7.1.250.0090.00215.97
7.1.240.0080.00516.14
7.1.230.0120.00514.95
7.1.220.0100.01115.06
7.1.210.0370.00614.86
7.1.200.0090.00715.45
7.1.190.0120.00515.00
7.1.180.0100.01015.05
7.1.170.0500.00814.45
7.1.160.0490.00514.63
7.1.150.0560.00914.69
7.1.140.0130.00414.67
7.1.130.0120.00614.85
7.1.120.0570.00614.78
7.1.110.0410.00714.68
7.1.100.0640.00814.65
7.1.90.0180.00614.48
7.1.80.0330.01014.58
7.1.70.0180.00615.41
7.1.60.0210.00924.50
7.1.50.0290.01024.46
7.1.40.0320.00924.24
7.1.30.0600.00824.27
7.1.20.0210.00724.28
7.1.10.0180.00515.25
7.1.00.0170.00715.22
7.0.330.0100.00315.45
7.0.320.0090.00315.36
7.0.310.0190.00514.60
7.0.300.0460.00814.06
7.0.290.0150.00914.15
7.0.280.0070.01014.66
7.0.270.0400.00914.28
7.0.260.0530.00914.21
7.0.250.0440.00814.17
7.0.240.0140.00614.33
7.0.230.0330.00714.25
7.0.220.0160.00714.25
7.0.210.0320.00514.27
7.0.200.0210.00514.89
7.0.190.0270.00714.94
7.0.180.0080.00914.87
7.0.170.0120.00714.89
7.0.160.0180.00714.87
7.0.150.0180.00614.76
7.0.140.0140.00614.85
7.0.130.0170.00615.07
7.0.120.0170.00615.00
7.0.110.0200.00814.92
7.0.100.0180.00614.78
7.0.90.0280.01314.71
7.0.80.0230.00714.88
7.0.70.0100.00814.85
7.0.60.0620.00714.88
7.0.50.0220.00814.93
7.0.40.0180.00614.10
7.0.30.0160.00714.06
7.0.20.0230.00614.06
7.0.10.0190.00414.07
7.0.00.0170.00614.13
5.6.400.0090.00014.47
5.6.390.0040.00414.68
5.6.380.0000.01214.09
5.6.370.0140.00514.42
5.6.360.0080.01014.60
5.6.350.0150.00514.37
5.6.340.0070.01114.66
5.6.330.0110.00614.42
5.6.320.0120.00714.39
5.6.310.0100.00914.40
5.6.300.0070.01916.13
5.6.290.0080.01716.05
5.6.280.0070.01716.19
5.6.270.0100.01516.20
5.6.260.0070.01716.06
5.6.250.0090.01416.08
5.6.240.0090.01916.13
5.6.230.0090.01416.00
5.6.220.0080.01716.13
5.6.210.0070.01716.19
5.6.200.0100.01616.15
5.6.190.0080.01715.96
5.6.180.0040.02016.06
5.6.170.0070.01616.04
5.6.160.0110.01116.07
5.6.150.0060.01716.00
5.6.140.0070.01916.02
5.6.130.0090.01615.99
5.6.120.0060.01716.04
5.6.110.0080.01415.95
5.6.100.0060.01916.10
5.6.90.0110.01716.03
5.6.80.0060.01815.90
5.6.70.0060.02515.95
5.6.60.0080.01715.98
5.6.50.0080.01615.83
5.6.40.0120.01815.95
5.6.30.0080.01615.65
5.6.20.0060.01915.71
5.6.10.0140.01215.93
5.6.00.0100.01415.81

preferences:
40.54 ms | 403 KiB | 5 Q