Color in php

Hello! I’m new here and this is my first question.

I have a php-file with the line:

echo $context['user']['name'], 

It displays the username of a logged in member in my forum. I want to set the color of the username to white #ffffff Is that possible?? :slight_smile:

yes, use css. Note that you shouldn’t use inline style, it should be pulled out into its own css file.

[php]<?= $context['user']['name'] ?>[/php]

Thanks JimL! I’m a real newbe to this. I have changed my code with yours and it didn’t help. It only gived me an php error. Where should I put your code? In the php file or in the css file?

[php]<?php

// your php code here

// then we should stop parsing php to output html

?>

<?= $context['user']['name'] ?>[/php]

If you’re still getting an error you’re probably on an older version of PHP that doesn’t support short echoes. Just change to this:

[php]<?php

// your php code here

// then we should stop parsing php to output html

?>

<?php echo $context['user']['name']; ?>[/php]

Hmm… No luck in putting the code at the end of the php file either…

Post your entire working code (including the span), there must be something else wrong.

The code is to big too put here and it’s not possible to upload php files in this forum. Strange!

I have zipped it. Hope that is ok.


index.template.zip (6.68 KB)

The code isn’t in that file.

Line 454

He, he! Ser nå at du er fra Norge! :slight_smile:

Yep…

You should’ve sent the code with the modification, without it I have no chance of knowing what you have done wrong.

Ok, here is the new file with the new line at the end of the file.


index.template2.zip (6.7 KB)

You should change line #454

from
[php]echo $context[‘user’][‘name’], ’ [/php]

to
[php]echo ‘’ . $context[‘user’][‘name’] . ', ’ [/php]

syntax error, unexpected ‘>’

[php]echo ‘’ . $context[‘user’][‘name’] . ‘’, ’ [/php]

Bingo! Thanks a lot, JimL! :slight_smile:

(Da er det natta her! :slight_smile: )

What if I wamt to change the font size to ex. 14 or 16. What should I do then?

Learn to look up stuff / learn some css

http://www.w3schools.com/css/css_font.asp

:stuck_out_tongue:

Sponsor our Newsletter | Privacy Policy | Terms of Service