Posted By

nogre on 07/31/11


Tagged

php random generator color


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

tux-world


Random color generator


 / Published in: PHP
 

  1. function randomColor() {
  2. $str = '#';
  3. for($i = 0 ; $i < 6 ; $i++) {
  4. $randNum = rand(0 , 15);
  5. switch ($randNum) {
  6. case 10: $randNum = 'A'; break;
  7. case 11: $randNum = 'B'; break;
  8. case 12: $randNum = 'C'; break;
  9. case 13: $randNum = 'D'; break;
  10. case 14: $randNum = 'E'; break;
  11. case 15: $randNum = 'F'; break;
  12. }
  13. $str .= $randNum;
  14. }
  15. return $str;
  16. }
  17. $color = randomColor();
  18. echo '<span style="color:'.$color.'">Random color: '.$color.'</span>';

Report this snippet  

You need to login to post a comment.