Php generates a summary of random color methods, and php generates a summary.
Method 1:
Generate a random color value (for example, FF00FF ).
Color. php
Copy codeThe 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 codeThe 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 codeThe 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 '<span style = "color: #'. randColor (). '"> random color: #'. randColor (). '</span>';?>