3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function toHex($n) { $n = intval($n); if (!$n) return '00'; $n = max(0, min($n, 255)); // make sure the $n is not bigger than 255 and not less than 0 $index1 = (int) ($n - ($n % 16)) / 16; $index2 = (int) $n % 16; return substr("0123456789ABCDEF", $index1, 1) . substr("0123456789ABCDEF", $index2, 1); } $r = 254; $g = 255; $b = 0; echo $hex = '#' . toHex($r) . toHex($g) . toHex($b); ?>
based on 0Rr8B
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
#FEFF00