Matthew Ellen .co .uk

Useful code snippets

StrToCol

define("BYTESPERCOLOUR", 3);
function StrToCol($input)
{
$result='';
$x = (strlen($input) < BYTESPERCOLOUR)?strlen($input):BYTESPERCOLOUR;
for($i = 0; $i < $x; $i++)
{
$hex = dechex(ord($input[$i]));
if (strlen($hex) < 2)
{
$hex = '0'.$hex;
}
$result = $result . $hex;
}
while (strlen($result) < (BYTESPERCOLOUR * 2))
{
$result = $result . '00';
}
return $result;
}

Back to the top

Back to code snippets