本文实例讲述了PHP十六进制颜色随机生成器功能。分享给大家供大家参考,具体如下:

<?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; ?>

运行结果:#8ABED4

相关推荐:

PHP函数之十进制、二进制、八进制和十六进制的转换

Js字符串相互转换十六进制的方法

php把十六进制值的字符串转换为ASCII字符的函数hex2bin()