Using sprintf() to ensure that one digit hex numbers (like 0) get padded with a leading 0.
function build_color($red, $green, $blue) {
$redhex = dechex($red);
$greenhex = dechex($green);
$bluehex = dechex($blue);
return sprintf('#%02s%02s%02s', $redhex, $greenhex, $bluehex);
}
Related examples in the same category