php生成随机颜色方法汇总_PHP
May 31, 2016 pm 06:15 PM方法一:
随机生成颜色值(例如 FF00FF).
color.php
代码如下:
function random_color(){
mt_srand((double)microtime()*1000000);
$c = '';
while(strlen($c)
$c .= sprintf("%02X", mt_rand(0, 255));
}
return $c;
}
方法二:
代码如下:
function randrgb()
{
$str='0123456789ABCDEF';
$estr='#';
$len=strlen($str);
for($i=1;$i
{
$num=rand(0,$len-1);
$estr=$estr.$str[$num];
}
return $estr;
}
方法三:
代码如下:
function randColor(){
$colors = array();
for($i = 0;$i
$colors[] = dechex(rand(0,15));
}
return implode('',$colors);
}
使用方法如下:
随机颜色:#'.randColor().'';?>

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
