944,106 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1863
  • PHP RSS
Oct 13th, 2007
0

Coloring text

Expand Post »
Hello everybody;

I want to color a text gradually by PHP

Explain: I want to color each letter with a color, like:

Hello: H=green e=red l=blue (And repeat) l=green o=red
Similar Threads
Reputation Points: 44
Solved Threads: 23
Posting Whiz
Pro2000 is offline Offline
350 posts
since Jun 2007
Oct 13th, 2007
0

Re: Coloring text

Surely this is a question to do with html then.
http://www.computerhope.com/htmcolor.htm
Last edited by iamthwee; Oct 13th, 2007 at 4:03 pm.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Oct 14th, 2007
0

Re: Coloring text

I think you did not understand me, I explain:
I wrote a chat program , I want when a user sends a message the message appears with mixed colors... the color of the first letter=green , the 2nd letter=red , the 3rd letter=blue and start over the 4th letter=green ,the 5th letter=red the 6th letter=blue and start over the 7th letter=green, 8th letter=red , 9th letter=blue .... until the message's end.
Reputation Points: 44
Solved Threads: 23
Posting Whiz
Pro2000 is offline Offline
350 posts
since Jun 2007
Oct 14th, 2007
0

Re: Coloring text

Honey you do realise the colour is rendered in html? The clever bit, i.e. first letter green second letter red, is done by writing code. Try it.
Last edited by iamthwee; Oct 14th, 2007 at 10:29 am.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Oct 14th, 2007
0

Re: Coloring text

here i got it. i just wrote the code and lightly tested it. to make it fit with your program i need to now where the string thats being colored is coming from (mysql, ect.)
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Oct 14th, 2007
0

Re: Coloring text

nevermind about the customizing. i made it into a function. lets say you have words contained in the variable $string, all you would have to do is call the function "color()" with the string that needs to be colored inside the parathesis ex. "color($string)" and the colored text will echoed onto the page.

Heres the color function code:

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. function color($str) {
  3. $i = 0;
  4. while ($i < strlen($str)) {
  5. $letters[] = substr($str, $i, 1);
  6. $i++;
  7. }
  8. $colors = array(0 => '<font color="green">',1 => '<font color="red">',2 => '<font color="blue">');
  9. $i = 0;
  10. $c = 0;
  11. while ($i < count($letters)) {
  12. if ($c == 3) {
  13. $c = 0;
  14. }
  15. echo $colors[$c] . $letters[$i] . '</font>';
  16. $i++;
  17. $c++;
  18. }
  19. }
  20. ?>
Last edited by kkeith29; Oct 14th, 2007 at 11:42 pm.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: desperate for password protection
Next Thread in PHP Forum Timeline: Session variables not carrying over to next page





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC