- strtr: documentation ( source)
- dechex: documentation ( source)
- hexdec: documentation ( source)
<?php
$white = hexdec('#ffffff');
//Loops for a bunch of colours
for( $i = 0 ; $i <= $white ; $i=$i+5000 )
{
//set default css background-color property
$backgroundValue = dechex( $i );
//if there are less of 7 characters (ex. #fa444, or #32F, ...)
if( $numLen = strlen( dechex( $i )) < 7 )
{
//insert (7 - numbers of characters) number of zeros after #
for ( $j = 0 ; $j < 7 - $numLen ; $j++ )
$backgroundValue = strtr( $backgroundValue, '#', '#0');
}
//echo each div with each background-color property.
echo '<div class="colour" style="width: 10%; float: left; background: #'.$backgroundValue.';">'.dechex($i).'</div>';
}