- dechex: documentation ( source)
- str_pad: documentation ( source)
<?php echo "Hello world"; ?>
<table>
<?php
//This is our first loop, changing the R value
$r=15;
while ($r <= 255)
{
echo "<tr>";
//Our third loop (B value) occurs 6 times for ever G value, or 216 times
$b=15;
while ($b <= 255)
{
//Here we actually generate the color blocks
$background = str_pad((string)dechex($r), 2, "0", STR_PAD_LEFT) . F . F . str_pad((string)dechex($b), 2, "0", STR_PAD_LEFT);
echo "<td bgcolor=\"#$background\">#$background</td>";
//At the end of each loop we add 3
$b = $b+16;
}
$r = $r+16;
echo "</tr>";
}
?>
</table>
<p>
<a href="http://www.goatella.com">Goatella's Home Page</a><p>
<a href="https://github.com/Goatella/PHP-Hex">This script on GitHub</a>