note 32434 added to function.hexdec
| From: | henrique at recidive dot com | Date: | Tue, 27 May 2003 20:43:41 +0000 |
| Subject: | note 32434 added to function.hexdec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-49111@lists.php.net to get a copy of this message | ||
Function to convert a string with hexadecimal colors to an associative array with RGB values:
<?
function hex2dec($hex) {
$color = str_replace('#', '', $hex);
$ret = array(
'r' => hexdec(substr($color, 0, 2)),
'g' => hexdec(substr($color, 2, 2)),
'b' => hexdec(substr($color, 4, 2))
);
return $ret;
}
/*** Example:
print_r(hex2dec('3D58BE'));
or
print_r(hex2dec('#3D58BE'));
will return
Array
(
[r] => 61
[g] => 88
[b] => 190
)
***/
?>
Thanks !
Henrique Recidive
----
Manual Page -- http://www.php.net/manual/en/function.hexdec.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32434
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32434&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32434&report=yes