(Solved) ..echo a text with a color stored in a variable?

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
hybris
Forum Contributor
Posts: 172
Joined: Wed Sep 25, 2013 4:09 am

(Solved) ..echo a text with a color stored in a variable?

Post by hybris »

I want a system where the username change with their rating.

I created a if - else if block to store different colorvalues in a variable like:

if (rating = 1) { $usrcolor='#FFFF444'; }

the if block is working... if i echo the $usrcolor variable it shows the correct #?????? value.

Now i want to do something like:

echo "<p style=\"font-color:$usrcolor; \">$username</p>";

but I cannot get it to work.

I think I messed up with the " or forgot some dot (like .$xxx)...

I tried alot of different ways to echo it but either i get it in black color or it wont echo at all..

please help I'm getting seriously frustrated heh.

Thanks
Last edited by hybris on Fri Oct 25, 2013 9:29 am, edited 1 time in total.
hybris
Forum Contributor
Posts: 172
Joined: Wed Sep 25, 2013 4:09 am

Re: How do you echo a text with a color stored in a variable

Post by hybris »

Solved it myself :)

echo "<span style=color:$namecolor class=\"label-$username\">$username</span>";
Post Reply