Page 1 of 1

0-1000, different colors

Posted: Fri Aug 22, 2008 9:30 am
by hameyekim
Hi everyone!

I just became a member and therefore it means It's my first post. I'm new to this PHP, so please do not be offended if my questions are too basic.

My question:

I need to print numbers from zero to 1000, with each of them in different color. But i could not find any code for PHP in which coloring is explained. I tried to apply HTML codes into <?php ?>, but again i am not sure if it works at all.

here is my code:

Code: Select all

<?php
for ($x=0; $x<=1000; $x++)
{
print $x . " ";
}
?>
Dont know what to do, would be happy if you could help me out.

Thanks

Re: 0-1000, different colors

Posted: Fri Aug 22, 2008 9:36 am
by ghurtado
You will have to print some HTML with the colors you want. Since HTML is all that ever gets returned to the browser (not PHP) PHP itself doesnt really display colors.

Re: 0-1000, different colors

Posted: Fri Aug 22, 2008 9:37 am
by onion2k
Well, you're printing the numbers fine. All you need to do now is work out how to print them in color (hint: use HTML <span> tags with a color in the style attribute), and then work out how to generate colors and put them in the style attribute of each span tag. That's the tricky bit really. You'll need to work out how to convert $x into a 6 character hex color if the first 1000 colors of the hex range are ok for you, or alternatively you'll need to work out how to generate a color gradient...