3v4l.org

run code in 300+ PHP versions simultaneously
<?php function swift_rgb2hex($rgb,$hash=true) { if($rgb == NULL){ return 'none'; } if($hash) $hex = '#'; $temp = explode('(',$rgb); var_dump($temp); if(!is_array($temp)){ return $rgb; } $rgb = $temp[1]; $rgb = explode(')',$rgb)[0]; $rgb = explode(',',$rgb); $hex .= str_pad(dechex($rgb[0]), 2, "0", STR_PAD_LEFT); $hex .= str_pad(dechex($rgb[1]), 2, "0", STR_PAD_LEFT); $hex .= str_pad(dechex($rgb[2]), 2, "0", STR_PAD_LEFT); return $hex; } echo swift_rgb2hex('rgba(0,0,0)'); echo swift_rgb2hex('boom'); echo swift_rgb2hex('FFFFFF'); echo swift_rgb2hex('rgba(0,0,0)');
Output for 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
array(2) { [0]=> string(4) "rgba" [1]=> string(6) "0,0,0)" } #000000array(1) { [0]=> string(4) "boom" } Warning: Undefined array key 1 in /in/qRFZS on line 14 Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /in/qRFZS on line 15 Fatal error: Uncaught TypeError: dechex(): Argument #1 ($num) must be of type int, string given in /in/qRFZS:18 Stack trace: #0 /in/qRFZS(18): dechex('') #1 /in/qRFZS(24): swift_rgb2hex(Array) #2 {main} thrown in /in/qRFZS on line 18
Process exited with code 255.
Output for 8.0.0 - 8.0.30
array(2) { [0]=> string(4) "rgba" [1]=> string(6) "0,0,0)" } #000000array(1) { [0]=> string(4) "boom" } Warning: Undefined array key 1 in /in/qRFZS on line 14 Fatal error: Uncaught TypeError: dechex(): Argument #1 ($num) must be of type int, string given in /in/qRFZS:18 Stack trace: #0 /in/qRFZS(18): dechex('') #1 /in/qRFZS(24): swift_rgb2hex(Array) #2 {main} thrown in /in/qRFZS on line 18
Process exited with code 255.
Output for 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
array(2) { [0]=> string(4) "rgba" [1]=> string(6) "0,0,0)" } #000000array(1) { [0]=> string(4) "boom" } Notice: Undefined offset: 1 in /in/qRFZS on line 14 Notice: Undefined offset: 1 in /in/qRFZS on line 19 Notice: Undefined offset: 2 in /in/qRFZS on line 20 #000000array(1) { [0]=> string(6) "FFFFFF" } Notice: Undefined offset: 1 in /in/qRFZS on line 14 Notice: Undefined offset: 1 in /in/qRFZS on line 19 Notice: Undefined offset: 2 in /in/qRFZS on line 20 #000000array(2) { [0]=> string(4) "rgba" [1]=> string(6) "0,0,0)" } #000000
Output for 7.3.32 - 7.3.33
array(2) { [0]=> string(4) "rgba" [1]=> string(6) "0,0,0)" } #000000array(1) { [0]=> string(4) "boom" } #000000array(1) { [0]=> string(6) "FFFFFF" } #000000array(2) { [0]=> string(4) "rgba" [1]=> string(6) "0,0,0)" } #000000
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/qRFZS on line 15
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/qRFZS on line 15
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/qRFZS on line 15
Process exited with code 255.

preferences:
234.2 ms | 401 KiB | 338 Q