View Full Version : PHP in HTML

03-05-2007, 08:13 PM
I'm developing a script for another forum, but I wonder if i can do this:

<?php if $variable=0 ?>
<html code in here>

I was wondering if that is possible or I need to describe what the variable will have to do first in the php tags, any help?

Thanks for the help

03-05-2007, 08:18 PM
Although I suggest you read some beginner tutorials, this is the way you'd do that.

if ($variable == 0) {
<p>The variable equals 0.</p>

(The indenting/newlines is not required, just makes it easier to read)

03-05-2007, 08:27 PM
Could you do something like this, (just wondering because I'm a beginner);

<?php if ($variable == 0) { ?>
<style> CSS code here </style>
<?php } ?>

Is this possible?

03-05-2007, 09:28 PM
Dragon Man,

Isn't that the same thing?

and also, you could do something like this:

$style="<div class='default'> CSS code here </class>";
if ($variable == 1) { $style="<div class='item1'> Something Else </class>"; }
if ($variable == 2) { $style="<div class='item2'> Something Else Here</class>"; }
More HTML here<br />

The mix/match of HTML and PHP can be done dozens of ways.
It's just important to know when to start/stop the PHP and decide
on echoing with PHP or "including PHP" with HTML.