A summary of methods to generate random colors in php, a summary of php generation
Method 1:
Randomly generate color values (e.g. FF00FF).
color.php
Copy code The code is as follows:
function random_color(){
mt_srand((double)microtime()*1000000);
$c = '';
While(strlen($c)<6){
$c .= sprintf("%02X", mt_rand(0, 255));
}
Return $c;
}
Method 2:
Copy code The code is as follows:
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;
}
Method 3:
Copy code The code is as follows:
function randColor(){
$colors = array();
for($i = 0;$i<6;$i++){
$colors[] = dechex(rand(0,15));
}
Return implode('',$colors);
}
How to use it:
Random color: #'.randColor().'';?>
http://www.bkjia.com/PHPjc/920970.html
www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/920970.htmlTechArticleA summary of PHP methods to generate random colors, PHP generation summary method one: Randomly generate color values (such as FF00FF). color. The php copy code is as follows: function random_color(){ mt_srand((doubl...