views:

36

answers:

2

the rgborhex function is returing an undefined variable:

function rgborhex($unformatedColor){
if(strpos($unformatedColor, "-") == false) { //did not find a - in the color string; is not in rgb form; convert
    $rgbColor = hextorgb($unformatedColor);
    $rgbColor = explode("-", $rgbColor);
    return $rgbColor;
}
else { // found a - in the color string; is in rgb form; return
    $rgbColor = $unformatedColor;
    $rgbColor = explode("-", $rgbColor);
    return $rbgColor;
}
}

function hextorgb($hex) {
if(strlen($hex) == 3) {
    $hrcolor = hexdec(substr($hex, 0, 1));      //r
    $hrcolor .= "-" . hexdec(substr($hex, 1, 1));   //g
    $hrcolor .= "-" . hexdec(substr($hex, 2, 1));   //b
}
else if(strlen($hex) == 6) {
    $hrcolor = hexdec(substr($hex, 0, 2));      //r
    $hrcolor .= "-" . hexdec(substr($hex, 2, 2)); //g
    $hrcolor .= "-" . hexdec(substr($hex, 4, 2)); //b
}
return $hrcolor;

}

+1  A: 
-return $rbgColor;
+return $rgbColor;

Just a typo in your second return statement :)


Alternative - minor edits, easier to read IMO:

function rgborhex($unformatedColor) {
    if (strpos($unformatedColor, '-') === false) { //did not find a - in the color string; is not in rgb form; convert
        $unformatedColor = hextorgb($unformatedColor);
    }

    return explode('-', $unformatedColor);
}
jensgram
Wow. Late night coding. that is what happened there! thanks!
Josh Brown
You're welcome :)
jensgram
A: 

Please put error_reporting on E_ALL | E_STRICT. This makes PHP to return much more errors than one might expect.

Snake