方法一:
function random_color(){ mt_srand((double)microtime()*1000000); $c = ''; while(strlen($c)<6){ $c .= sprintf("%02X", mt_rand(0, 255)); } return $c; }
方法二:
function randrgb() { $str='0123456789ABCDEF'; $estr='#'; $len=strlen($str); for($i=1;$i<=6;$i++) { $num=rand(0,$len-1); $estr=$estr.$str[$num]; } return $estr; }
方法三:
function randColor(){ $colors = array(); for($i = 0;$i<6;$i++){ $colors[] = dechex(rand(0,15)); } return implode('',$colors); }