Pad with leading zeroes:
<? $red = 1; $green = 1; $blue = 1; printf( "#%02x%02x%02x", $red, $green, $blue); ?>
Maths: %d; English: %d; History: %d; Biology: %d.
and