3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // http://en.wikipedia.org/wiki/HSL_and_HSV#Converting_to_RGB function strtocolour($tstr) { $crc = unpack('L', hash('crc32', $tstr, true))[1]; $Hp = $crc / (0xFFFFFFFF / 6); $S = 0.8; // change as desired $V = 0.8; // change as desired $C = $V*$S; $X = $C*(1 - abs(fmod($Hp, 2) - 1)); $m = $V - $C; $i = 1+min(5, intval($Hp)); $comp = [ [$C, $X, 0], [$X, $C, 0], [ 0, $C, $X], [ 0, $X, $C], [$X, 0, $C], [$C, 0, $X]][$i]; $r = intval(255*($m + $comp[0])); $g = intval(255*($m + $comp[1])); $b = intval(255*($m + $comp[2])); return sprintf("#%02X%02X%02X", $r, $g, $b); } function test($tstr) { echo '<span style="color:"'.strtocolour($tstr).'">'; echo htmlspecialchars($tstr); echo '</span>'; } test('I'); test('am'); test('a'); test('fluffy'); test('bunny'); ?>
Output for 5.5.24 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
<span style="color:"#3428CC">I</span><span style="color:"#CC28BE">am</span><span style="color:"#8ACC28">a</span><span style="color:"#A6CC28">fluffy</span><span style="color:"#CC2899">bunny</span>
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '[' in /in/NYNX9 on line 19
Process exited with code 255.
Output for 5.3.7 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/NYNX9 on line 5
Process exited with code 255.