Skip to content

Instantly share code, notes, and snippets.

@YurePereira
Created October 6, 2016 15:43
Show Gist options
  • Select an option

  • Save YurePereira/10b82cb9e3d3a4e18fcac023828b564f to your computer and use it in GitHub Desktop.

Select an option

Save YurePereira/10b82cb9e3d3a4e18fcac023828b564f to your computer and use it in GitHub Desktop.
Converte código HTML hexadecimal para decimal.
/**
* Converte código HTML hexadecimal para decimal.
*
* @param $code String código HTML hexadecimal.
*
* @return Array
*/
function hexaHtmlToDecimal($code) {
if (strlen($code) == 7) {
$code = str_replace('#', '', $code);
$codeR = substr($code, 0, 2);
$codeG = substr($code, 2, 2);
$codeB = substr($code, 4, 2);
return array(
'r' => hexdec($codeR),
'g' => hexdec($codeG),
'b' => hexdec($codeB)
);
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment