随机生成颜色值(例如 #FF00FF):
方法1:
function randColor(){
mt_srand((double)microtime()*1000000);
$c = '';
while(strlen($c)<6){
$c .= sprintf("%02X", mt_rand(0, 255));
}
return '#'.$c;
}
方法2:
function randColor() {
$str='0123456789ABCDEF';
$strs='#';
$len=strlen($str);
for($i=1;$i<=6;$i++){
$num=rand(0,$len-1);
$strs=$strs.$str[$num];
}
return $strs;
}
方法3:
function randColor(){
$cs = array();
for($i = 0;$i<6;$i++){
$cs[] = dechex(rand(0,15)); //dechex()把十进制转换为十六进制
}
$c = implode('',$cs);
return '#'.$c;
}