private static function parseHue($input, &$result)
    {
        if (preg_match(
            '/^\s*(\d*(?:\.\d*)?)(deg|grad|rad|turn|)\s*$/', 
            $input, $matches)
        ) {
            $result = floatval($matches[1]);
            
            // Percentage
            switch ($matches[2]) {
                case "grad":
                    // Gradians: range 0 - 400
                    $result = $result / 400;
                    break;
                case "rad":
                    // Radians: range 0 - 2pi
                    $result = $result / M_PI / 2;
                    break;
                case "turn":
                    // Turns: range 0 - 1
                    $result = $result;
                    break;
                default:
                    // Degree: range 0 - 360
                    $result = $result / 360;
                    break;
            }
            
            $result = fmod($result, 1);
            
            if ($result < 0) {
                $result += 1;
            }
            
            return true;
        }
        return false;
    }
private static function parseHue($input, &$result)
    {
        if (preg_match(
            '/^\s*(\d*(?:\.\d*)?)(deg|grad|rad|turn|)\s*$/', 
            $input, $matches)
        ) {
            $result = floatval($matches[1]);
            
            // Percentage
            switch ($matches[2]) {
                case "grad":
                    // Gradians: range 0 - 400
                    $result = $result / 400;
                    break;
                case "rad":
                    // Radians: range 0 - 2pi
                    $result = $result / M_PI / 2;
                    break;
                case "turn":
                    // Turns: range 0 - 1
                    $result = $result;
                    break;
                default:
                    // Degree: range 0 - 360
                    $result = $result / 360;
                    break;
            }
            
            $result = fmod($result, 1);
            
            if ($result < 0) {
                $result += 1;
            }
            
            return true;
        }
        return false;
    }
private static function parseHue ( $ input , & $ result ) { if ( preg_match ( '/^\s*(\d*(?:\.\d*)?)(deg|grad|rad|turn|)\s*$/' , $ input , $ matches ) ) { $ result = floatval ( $ matches [ 1 ] ) ; // Percentage switch ( $ matches [ 2 ] ) { case "grad" : // Gradians: range 0 - 400 $ result = $ result / 400 ; break ; case "rad" : // Radians: range 0 - 2pi $ result = $ result / M_PI / 2 ; break ; case "turn" : // Turns: range 0 - 1 $ result = $ result ; break ; default : // Degree: range 0 - 360 $ result = $ result / 360 ; break ; } $ result = fmod ( $ result , 1 ) ; if ( $ result < 0 ) { $ result += 1 ; } return true ; } return false ; }
Parses a hue component.

@param string $input Input string.
@param float $result Hue in range [0, 1].

@return boolean
Parses a hue component .