note 51270 added to function.hexdec

From: Date: Fri, 25 Mar 2005 07:26:02 +0000
Subject: note 51270 added to function.hexdec
Groups: php.notes 
Request: Send a blank email to php-notes+get-86933@lists.php.net to get a copy of this message
A small 'convert color' class .. <?php /** * Convert colors * * Usage: * color::hex2rgb("FFFFFF") * color::rgb2hex(array(171,37,37)) * * @author Tim Johannessen <root@it.dk> * @version 1.0.0 */ class color { /** * Convert HEX colorcode to an array of colors. * * @author Tim Johannessen <admin@stillborn.dk> * @return array Returns the array of colors as array(red,green,blue) */ function hex2rgb($hexVal = "") { $hexVal = eregi_replace("[^a-zA-Z0-9]", "", $hexVal); if (strlen($hexVal) != 6) { return "ERR: Incorrect colorcode."; } $arrTmp = explode(" ", chunk_split($hexVal, 2, " ")); $arrTmp = array_map("hexdec", $arrTmp); return array("red" => $arrTmp[0], "green" => $arrTmp[1], "blue" => $arrTmp[2]); } /** * Convert RGB colors to HEX colorcode * * @author Tim Johannessen <admin@stillborn.dk> * @return hex Returns the converted colors as a 6 digit colorcode */ function rgb2hex($arrColors = null) { if (!is_array($arrColors)) { return "ERR: Invalid input, expecting an array of colors"; } if (count($arrColors) < 3) { return "ERR: Invalid input, array too small (3)"; } array_splice($arrColors, 3); $arrColors = array_map("dechex", $arrColors); return implode("", $arrColors); } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.hexdec.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51270 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51270&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51270&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51270&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51270&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51270&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51270&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86933) next »