Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

random string generator with each lines different color

I’m trying to create in PHP a randomized string script, but complex, because each line must have a different color, the color is not important, it can be random, but should not be the same twice.
The output must be something like this :

Hello#in blue color
Hello#in red color
Hello#in pink color

i’ve tried with the str_repeat function,

echo "Colored random String Generator";
echo "<br>";
echo str_repeat("Hello <br>", 100);

but there are too few parameters, i can’t really put a <span style="color:$randomColor> between them

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Did i miss something ?

>Solution :

You may need to tweak the random color generator as I chucked it together but this is basically what you are after I believe:

function randomColor() {
    return str_pad(dechex(rand(0x000000, 0xFFFFFF)), 6, 0, STR_PAD_LEFT);
}

echo "Colored random String Generator<br>";

$repeatCount = 100;

for ($x = 0; $x <= $repeatCount; $x++) {
  echo "<span style=\"color: #".randomColor().";\">Hello</span> <br>";
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading