Php generate a summary of random color methods, php generate a summary _ PHP Tutorial

Source: Internet
Author: User
Php generates a summary of random color methods, and php generates a summary. Php generates a summary of the random color method. php generates a summary method. Method 1: generate a random color value (for example, FF00FF ). color. the php copy code is as follows: functionrandom_color () {mt_srand (doubl php generates a random color method summary, php generates a summary

Method 1:
Generate a random color value (for example, FF00FF ).

Color. php

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:

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:

The code is as follows:


Function randColor (){
$ Colors = array ();
For ($ I = 0; $ I <6; $ I ++ ){
$ Colors [] = dechex (rand (0, 15 ));
}
Return implode ('', $ colors );
}

The usage is as follows:
<? Php echo 'random color: # '. randColor (). '';?>

Method 1: randomly generate a color value (for example, FF00FF). the color. php code is as follows: function random_color () {mt_srand (doubl...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.