up vote 0 down vote favorite

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;

}

link|flag

57% accept rate
2  
With your strpos you should check === false, not == false. – Psytronic Feb 5 at 8:32

2 Answers

up vote 1 down vote accepted
-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);
}
link|flag
Wow. Late night coding. that is what happened there! thanks! – Josh Brown Feb 5 at 8:35
You're welcome :) – jensgram Feb 5 at 8:35
up vote 0 down vote

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

link|flag

Your Answer

get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.