Coloring text

Reply

Join Date: Jun 2007
Posts: 71
Reputation: Pro2000 is an unknown quantity at this point 
Solved Threads: 1
Pro2000's Avatar
Pro2000 Pro2000 is offline Offline
Junior Poster in Training

Coloring text

 
0
  #1
Oct 13th, 2007
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
The great scientist see his web-site:
http://www.elnaggarzr.com/en
I'm sure that will be good for you!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Coloring text

 
0
  #2
Oct 13th, 2007
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.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 71
Reputation: Pro2000 is an unknown quantity at this point 
Solved Threads: 1
Pro2000's Avatar
Pro2000 Pro2000 is offline Offline
Junior Poster in Training

Re: Coloring text

 
0
  #3
Oct 14th, 2007
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.
The great scientist see his web-site:
http://www.elnaggarzr.com/en
I'm sure that will be good for you!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Coloring text

 
0
  #4
Oct 14th, 2007
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.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Coloring text

 
0
  #5
Oct 14th, 2007
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.)
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Coloring text

 
0
  #6
Oct 14th, 2007
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:

  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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC