Quick Question about changing font colour within PHP
Moderator: General Moderators
Quick Question about changing font colour within PHP
I can change the colour, font, size etc in html, but how do I do it using PHP, or do I have to go between php and html in order to do it?
an example would be nice if you've got one.
an example would be nice if you've got one.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
- Fredix
- Forum Contributor
- Posts: 101
- Joined: Fri Jul 18, 2003 2:16 pm
- Location: Wehr (Eifel) Germany
- Contact:
just to add some details:
all your echo (or print) commands should contain is some html stuff that you send as a result to your client's browser.
So to solve your problem use
echo "<span style=\"color:#FF0000\">red</span>";
I use a backslash before the "" in the style attribute to tell php that those " don't mark the end of the echo argument, when working on your code PHP will internetpret it and delete all the php stuff so in the end you will see
<span style="color:#FF0000">red</span>
as the source code
hope I helped you
all your echo (or print) commands should contain is some html stuff that you send as a result to your client's browser.
So to solve your problem use
echo "<span style=\"color:#FF0000\">red</span>";
I use a backslash before the "" in the style attribute to tell php that those " don't mark the end of the echo argument, when working on your code PHP will internetpret it and delete all the php stuff so in the end you will see
<span style="color:#FF0000">red</span>
as the source code
hope I helped you
You know, you don't have to add thoses backslashes. I use a GUI to program, Dreamweaver MX, and thoses slashes screw with it's display in the preview window so i switch between PHP and regular HTML sometimes in my scripts.
Code: Select all
<?php
// some PHP code
?>
<span style="color:#<?php echo $colorcode; ?>"><?php echo $color; ?></span>
<?php
// more PHP code
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Just to add to this, you can also use single quotes around the echo:Sami wrote:You know, you don't have to add thoses backslashes. ... i switch between PHP and regular HTML sometimes in my scripts.
Code: Select all
echo '<span style="color: #FF0000;">red</span>';Code: Select all
echo <<<END
<span style="color: #FF0000;">red</span>
END;http://www.php.net/manual/en/language.types.string.php
Mac
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Normally I prefer people to start new posts rather than add to old ones and reference the old post in the new topic (see the guidelines link in my signature). However, for this topic I mind not as the original posted has moved their problem onto a new thread.
Now to actually answer the question: yes it's just personal preference, I prefer heredoc syntax as it removed the need for escaping quotes, I can enter my variables in without the need for concenation and I can keep the flow of my PHP (I tend to find going in and out of PHP means I mess up on closing braces for loops and conditionals) plus of course my HTML is nicely formateed. The most important thing, however, is to be consistent with how you deal with blocks of HTML so that debugging is easier.
Mac
Now to actually answer the question: yes it's just personal preference, I prefer heredoc syntax as it removed the need for escaping quotes, I can enter my variables in without the need for concenation and I can keep the flow of my PHP (I tend to find going in and out of PHP means I mess up on closing braces for loops and conditionals) plus of course my HTML is nicely formateed. The most important thing, however, is to be consistent with how you deal with blocks of HTML so that debugging is easier.
Mac