Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Random Font Colors

Tags:

javascript

php

I need to color text with 2 or 3 random colors. How can I do this in PHP or JavaScript?

like image 862
Saska Avatar asked Dec 08 '25 01:12

Saska


2 Answers

$color = str_pad(sprintf("%x%x%x", rand(0,255), rand(0,255), rand(0,255)),6,rand(0,9));
echo '<span style="color:'.$color.'">Random Color</span>';

Provides random #<Red><green><blue> color

like image 112
Brad Christie Avatar answered Dec 10 '25 14:12

Brad Christie


This should do the trick:

function getRandomColour() {
    return 'red';      // chosen by fair dice roll
                       // guaranteed to be random
}

Courtesy of XKCD, for those of you who are new around here.

like image 35
Alnitak Avatar answered Dec 10 '25 15:12

Alnitak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!