3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getContrastYIQ($hexcolor){ $r = hexdec(substr($hexcolor,0,2)); $g = hexdec(substr($hexcolor,2,2)); $b = hexdec(substr($hexcolor,4,2)); $yiq = (($r*299)+($g*587)+($b*114))/1000; return ($yiq >= 128) ? 'black' : 'white'; } $color = getContrastYIQ(); if(empty($color)) { echo "Empty"; }

preferences:
49.99 ms | 402 KiB | 5 Q