0-1000, different colors

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hameyekim
Forum Newbie
Posts: 1
Joined: Fri Aug 22, 2008 9:23 am

0-1000, different colors

Post 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
Last edited by onion2k on Fri Aug 22, 2008 9:33 am, edited 1 time in total.
Reason: Moved to the PHP-Code forum, added code tags for highlighting.
User avatar
ghurtado
Forum Contributor
Posts: 334
Joined: Wed Jul 23, 2008 12:19 pm

Re: 0-1000, different colors

Post 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.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: 0-1000, different colors

Post 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...
Post Reply