function color_txt($str){
if ( is_array($str) )
{
$str = $str[1];
}
$len = mb_strlen($str);
$colorTxt = '';
for($i=0; $i<$len; $i++) {
$colorTxt .= '<span style="color:'.rand_color().'">'.mb_substr($str,$i,1,'utf-8').'</span>';
}
return $colorTxt;
}
function rand_color(){
return '#'.sprintf("%02X",mt_rand(0,255)).sprintf("%02X",mt_rand(0,255)).sprintf("%02X",mt_rand(0,255));
}
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);
}
/**
* 随机颜色生成
* @author LJ
* @date 2017-02-09
*/
function randomColor() {
// 颜色 例:#866573
$str = '#';
for($i = 0 ; $i < 6 ; $i++) {
$randNum = rand(0 , 15);
switch ($randNum) {
case 10:
$randNum = 'A';
break;
case 11:
$randNum = 'B';
break;
case 12:
$randNum = 'C';
break;
case 13:
$randNum = 'D';
break;
case 14:
$randNum = 'E';
break;
case 15:
$randNum = 'F';
break;
}
$str .= $randNum;
}
return $str;
}
$color = randomColor();
<?php
function randColor(){
$colors=array('5CB85C','428BCA','FF6600','D9534F','B37333','00ABA9');
$show_color = array_rand($colors, 1);
return $colors[$show_color];
}
?>
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛