•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,536 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,073 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 831 | Replies: 5
![]() |
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
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!
http://www.elnaggarzr.com/en
I'm sure that will be good for you!
Surely this is a question to do with html then.
http://www.computerhope.com/htmcolor.htm
http://www.computerhope.com/htmcolor.htm
Last edited by iamthwee : Oct 13th, 2007 at 4:03 pm.
... the hat of 'is this a cat in a hat?'
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.
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!
http://www.elnaggarzr.com/en
I'm sure that will be good for you!
•
•
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation:
Rep Power: 3
Solved Threads: 72
•
•
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation:
Rep Power: 3
Solved Threads: 72
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:
Heres the color function code:
<?php
function color($str) {
$i = 0;
while ($i < strlen($str)) {
$letters[] = substr($str, $i, 1);
$i++;
}
$colors = array(0 => '<font color="green">',1 => '<font color="red">',2 => '<font color="blue">');
$i = 0;
$c = 0;
while ($i < count($letters)) {
if ($c == 3) {
$c = 0;
}
echo $colors[$c] . $letters[$i] . '</font>';
$i++;
$c++;
}
}
?> Last edited by kkeith29 : Oct 14th, 2007 at 11:42 pm.
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Questions For WebDevelopment =) (HTML and CSS)
- DreamWeaver a Tool or not? (Web Developers' Lounge)
- Practice problem (C++)
- How to do text fade in and fade out effect (C)
- inserting coloring text (MS SQL)
- I need special stuff in my project like system("cls") (C++)
- connect to text file database (Visual Basic 4 / 5 / 6)
Other Threads in the PHP Forum
- Previous Thread: desperate for password protection
- Next Thread: Session variables not carrying over to next page



Linear Mode