A simple way to generate random colors in php

WBOY
Release: 2016-07-29 08:51:40
Original
1118 people have browsed it

The example in this article describes how to simply generate random colors in PHP. Share it with everyone for your reference, the details are as follows:

<&#63;php
  //第一种方法:
   $rand = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
  $color = '#'.$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)];
  echo $color."<br/>"; 
  //第二种方法:
   printf( "#%06X\n", mt_rand( 0, 0xFFFFFF ));
?>

Copy after login

The running results are as follows:

#4338cd
#7EF5B8 

Copy after login

For color value conversion and acquisition, you can also refer to the online tool of this site:

RGB Color Coding Generator

Online web color matching tool

RGB color query comparison table_Color code table_Complete English names of colors

Readers who are interested in more PHP-related content can check out this site's special topic: "Complete PHP Array (Array) Operation Skills" ", "Summary of PHP mathematical operation skills", "Summary of PHP graphics and image operation skills", "Summary of PHP office document operation skills (including word, excel, access, ppt)", "Summary of PHP date and time usage", "php "Object-oriented programming introductory tutorial", "php string (string) usage summary", "php+mysql database operation introductory tutorial" and "php common database operation skills summary"

I hope that this article will be helpful to everyone's PHP programming design help.

The above introduces how to simply generate random colors in PHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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 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!