note 117197 added to function.dechex

From: Date: Thu, 30 Apr 2015 14:44:00 +0000
Subject: note 117197 added to function.dechex
Groups: php.notes 
Request: Send a blank email to php-notes+get-202401@lists.php.net to get a copy of this message
I like the example with the bitwise operations but if the value of color[0] is less than 16 it's not accurate: example: color[0]: 0; color[1]: 0; color[2]: 255; function hexColor($color) { return dechex(($color[0]<<16)|($color[1]<<8)|$color[2]); } It returns "ff", which is not legit RGB color... so my solution is to combine the function above with: function toColor($n) { return("#".substr("000000".dechex($n),-6)); } If you gotta deal with array of rgb values this is my solution: ------------------------------------------------------ function hexColor($color) { $rgb = dechex(($color[0]<<16)|($color[1]<<8)|$color[2]); return("#".substr("000000".$rgb, -6)); } ------------------------------------------------------ ---- Server IP: 72.52.91.14 Probable Submitter: 95.111.38.241 ---- Manual Page -- http://php.net/manual/en/function.dechex.php Edit -- https://master.php.net/note/edit/117197 Del: integrated -- https://master.php.net/note/delete/117197/integrated Del: useless -- https://master.php.net/note/delete/117197/useless Del: bad code -- https://master.php.net/note/delete/117197/bad+code Del: spam -- https://master.php.net/note/delete/117197/spam Del: non-english -- https://master.php.net/note/delete/117197/non-english Del: in docs -- https://master.php.net/note/delete/117197/in+docs Del: other reasons-- https://master.php.net/note/delete/117197 Reject -- https://master.php.net/note/reject/117197 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#202401) next »