note 58253 added to function.hexdec

From: Date: Fri, 28 Oct 2005 20:59:24 +0000
Subject: note 58253 added to function.hexdec
Groups: php.notes 
Request: Send a blank email to php-notes+get-97771@lists.php.net to get a copy of this message
A handy little function to convert HEX colour codes to "web safe" colours... <?php function color_mkwebsafe ( $in ) { // put values into an easy-to-use array $vals['r'] = hexdec( substr($in, 0, 2) ); $vals['g'] = hexdec( substr($in, 2, 2) ); $vals['b'] = hexdec( substr($in, 4, 2) ); // loop through foreach( $vals as $val ) { // convert value $val = ( round($val/51) * 51 ); // convert to HEX $out .= str_pad(dechex($val), 2, '0', STR_PAD_LEFT); } return $out; } ?> Example: color_mkwebsafe('0e5c94'); Produces: 006699 Hope this helps someone out... Happy coding. :-) ---- Manual Page -- http://www.php.net/manual/en/function.hexdec.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+58253 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58253&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58253&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58253&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58253&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58253&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58253&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58253&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+58253&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#97771) next »