MasterKaos
Programmer
Ok, i had a very similar question a few days ago about leading zeroes in integers, and it was pointed out that the sprintf() function did this no problems.
But what about hexadecimals? I'm writing a function that takes an array with three integers (one each for red, green, blue) and creates a 6 digit hexadecimal colour code to be used in HTML:
but the problem is single digit numbers mess the whole thing up, for example "F0F" won;t work in HTML, it would have to be "0F000F" for HTML.
Any ideas how to do this?
----------------------------------------------------------------------------
The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.
But what about hexadecimals? I'm writing a function that takes an array with three integers (one each for red, green, blue) and creates a 6 digit hexadecimal colour code to be used in HTML:
Code:
$colour = array(r=>254, g=>213, b=>0);
...
function tohex($colour)
{
$output="";
$output.= dechex($colour[r]);
$output.= dechex($colour[g]);
$output.= dechex($colour[b]);
return $output;
}
but the problem is single digit numbers mess the whole thing up, for example "F0F" won;t work in HTML, it would have to be "0F000F" for HTML.
Any ideas how to do this?
----------------------------------------------------------------------------
The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.