Public feed #599961

Geoffrey Sneddon

public php v1 · immutable
Raw Edit
·published 2007-07-02 15:14 UTC
rendered paste body
<?php/** * See if a string is a valid hexadecimal colour * * @param string $str Input String * @return bool Returns true if str is a valid hexadecimal colour, false otherwise */function valid_hex_colour($str){	$len = strlen($str);	if (($len == 4 || $len == 7) && $str[1] == '#' && strspn(substr($str, 1), '0123456789abcdefABCDEF') == $len - 1)	{		return true;	}	else	{		return false;	}}if (valid_hex_colour('#DDd')){	echo 'valid!';}else{	echo 'invalid!';}