PDA

View Full Version : How do you style php code?



elliot
09-10-2005, 09:42 AM
Maybe a very lame question, though I haven't a clue..

I've got my form to work, though would like to style it if poss, with a bold title, coloured heading.

Can you do this?

this is the form if it helps
http://www.clippergems.com/who.html

thanks very much guys,
Elliot

Twey
09-10-2005, 10:15 AM
You don't style the PHP code, you style the HTML it outputs. Just link to a CSS file as you would any HTML page.

P.S.
"What's is a ClipperGem?"
should be
"What is a ClipperGem?"

elliot
09-10-2005, 09:03 PM
Whoops! :eek: luckily this site isn't live yet....
First thing I did was changed the top nav. I'll be extra thourough before I let the public see it :)

When you said just style the HTML it outputs, should I be styling the HTML within the <?php ?> tags with whatever I need like so.....?

<?php
<h2>Title</h2>
<p class="blue">text</p>
?>

thanks very much mate

Twey
09-10-2005, 09:34 PM
Yep, more or less. Obviously you wouldn't put HTML directly in the PHP tags as you did there, though. I'm presuming that was an example.

elliot
09-10-2005, 09:54 PM
I'm presuming that was an example

actually I'm a bit confused with this. Could you please give me an example, as my example was in fact my interpretation, which is wrong :confused: . Sorry mate

Twey
09-10-2005, 10:23 PM
<?php
# do PHP stuff
echo("<p class=\"blue\">");
?>
</p>
<p class="red">
</p>

mpcow
11-03-2009, 01:17 PM
How would this work if I wanted to style variables? So for example, the variables would be bold within a paragraph that has the variables in it when it is printed?

bluewalrus
11-03-2009, 02:03 PM
The simplist way I'm think of would be put span tags around them and either style each or make a class if they are all the same styles.

example
<style type="text/css">
.bold {
font-weight:bold;
}
</style>
<?php
$name = "You didn't enter a name";
some other php stuff
if ($name <> "You didn't enter a name" ) {
echo "$something <h1> Your name is: <span class=\"bold\">$name</span>";
}
else {
echo "<span class=\"bold\">$name</span>";
}

djr33
11-03-2009, 05:48 PM
PHP ONLY generates html. A valid PHP page does NOT need to contain PHP tags at all, in fact. It can just be normal html, without any added PHP.

Between PHP tags you only have PHP code. Outside of the PHP tags you have normal HTML, Javascript, CSS, etc.

If you need to output HTML, etc., from within PHP tags, do so using echo or another method (depending on how you PHP works).

Look at Twey's example above. It shows both methods.

You can either output all the text directly from within PHP (the post above mine) or you can just output parts, like this:
<span>Some text <b><?php echo $boldtext; ?></b> more text </span>
Likely, <b> is not the best method in HTML, but that has nothing to do with the PHP code.

Please review the information here, if any of this is not clear.
http://dynamicdrive.com/forums/showthread.php?t=25847

In general you need to start thinking of PHP as just an html generator, so generate html however you would like, using PHP as a tool to output text how and where you should like.

newbtophp
11-04-2009, 04:15 AM
Erm why don't you use highlight_string() ?

traq
11-04-2009, 05:23 AM
I don't think he wants to style the php code, but the content of his website, which is done by applying css to the output html.

PHP can be used to generate the html (or even the css), but the function highlight_string() has nothing to do with that (http://us.php.net/manual/en/function.highlight-string.php).

BTW, if you even needed to use highlight_string(), I would recommend simply downloading Notepad++ (http://notepad-plus.sourceforge.net/uk/site.htm). It applies similar highlighting as you type - very useful for keeping track of your syntax