note 80796 added to function.hexdec
| From: | WalterWlodarski at osu1 dot php dot net | Date: | Thu, 31 Jan 2008 21:33:17 +0000 |
| Subject: | note 80796 added to function.hexdec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135679@lists.php.net to get a copy of this message | ||
One of my favourite, multi-purpose, bidirectional solution I wrote many years ago:
function bgr2rgb($cr) { // bidirectional
return (($cr & 0x0000FF) << 16 | ($cr & 0x00FF00) | ($cr & 0xFF0000) >>
16);
}
Which you might want to use as :
function hex2cr($hex) { // strips any leading characters, like #
return bgr2rgb(hexdec($hex));
}
function cr2hex($cr) { // the usual HTML format, #rrggbb
return '#'.str_pad(strtoupper(dechex(bgr2rgb($cr))), 6, '0', STR_PAD_LEFT);
}
And, if like me you tend to mistype function names, the synonym :
function rgb2bgr($val) { return bgr2rgb($val); }
----
Server IP: 216.235.15.211
Probable Submitter: 64.235.215.208
----
Manual Page -- http://www.php.net/manual/en/function.hexdec.php
Edit -- https://master.php.net/note/edit/80796
Del: integrated -- https://master.php.net/note/delete/80796/integrated
Del: useless -- https://master.php.net/note/delete/80796/useless
Del: bad code -- https://master.php.net/note/delete/80796/bad+code
Del: spam -- https://master.php.net/note/delete/80796/spam
Del: non-english -- https://master.php.net/note/delete/80796/non-english
Del: in docs -- https://master.php.net/note/delete/80796/in+docs
Del: other reasons-- https://master.php.net/note/delete/80796
Reject -- https://master.php.net/note/reject/80796
Search -- https://master.php.net/manage/user-notes.php