Daniel St. Jules Posted July 19, 2008 Share Posted July 19, 2008 I'm trying to convert a Hex colour value to RGB using a function I found at http://www.anyexample.com/programming/php/php_convert_rgb_from_to_html_hex_color.xml Here's the code: function html2rgb($color){ if ($color[0] == '#') $color = substr($color, 1); if (strlen($color) == 6) list($r, $g, $b) = array($color[0].$color[1],$color[2].$color[3],$color[4].$color[5]); elseif (strlen($color) == 3) list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]); else return false; $r = hexdec($r); $g = hexdec($g); $b = hexdec($b); return array($r, $g, $b); } $textcolour = addslashes($_POST["textcolour"]); $colouroftext = html2rgb($textcolour); echo "Text colour: $textcolour <br /> $colouroftext[0],$colouroftext[1],$colouroftext[2]"; The problem is, when I try to print the RGB values, only $colouroftext[0] and $colouroftext[1] work. $colouroftext[2] keeps showing empty, and I can't figure out why. Any help would be greatly appreciated in solving this. Thanks. Link to comment https://forums.phpfreaks.com/topic/115612-solved-trouble-with-arrays-output-of-function/ Share on other sites More sharing options...
ignace Posted July 19, 2008 Share Posted July 19, 2008 empty or 0 is the same thing Link to comment https://forums.phpfreaks.com/topic/115612-solved-trouble-with-arrays-output-of-function/#findComment-594313 Share on other sites More sharing options...
Daniel St. Jules Posted July 19, 2008 Author Share Posted July 19, 2008 But it shouldn't be empty. Here's an example. I input: 735856 The output ends up being: 115,88, Where as it should be: 115,88,86 For some reason $colouroftext[2] is always returning empty when it shouldn't, which is why I'm asking for help, cause I really have no idea why. Thanks again. -Edit: Nevermind, I think I figured it out. Link to comment https://forums.phpfreaks.com/topic/115612-solved-trouble-with-arrays-output-of-function/#findComment-594321 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.