Summary of methods for generating random colors in php, summary of php generation_PHP tutorial

WBOY
Release: 2016-07-13 10:12:26
Original
849 people have browsed it

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

truehttp: //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...
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!