This article mainly introduces the PHP hexadecimal color random generator function, and analyzes the relevant operating skills of PHP to randomly generate hexadecimal numerical representations based on specific examples. Friends in need can refer to the following
The example in this article describes the PHP hexadecimal color random generator function. Share it with everyone for your reference, the details are as follows:
<?php function randomColor() { $str = '#'; for($i = 0 ; $i < 6 ; $i++) { $randNum = rand(0 , 15); switch ($randNum) { case 10: $randNum = 'A'; break; case 11: $randNum = 'B'; break; case 12: $randNum = 'C'; break; case 13: $randNum = 'D'; break; case 14: $randNum = 'E'; break; case 15: $randNum = 'F'; break; } $str .= $randNum; } return $str; } $color = randomColor(); echo $color; ?>
Running results: #8ABED4
##Related recommendations:
PHP function conversion of decimal, binary, octal and hexadecimal
Js string conversion methodHexadecimal
php function hex2bin() that converts a string of hexadecimal values into ASCII characters
The above is the detailed content of How to implement hexadecimal color random generator function in PHP. For more information, please follow other related articles on the PHP Chinese website!