...

View Full Version : PHP in HTML



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

<html>
<body>
<?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

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



<body>
<?php
if ($variable == 0) {
?>
<p>The variable equals 0.</p>
<?php
}
?>
</body>


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

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


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


Is this possible?

mlseim
03-05-2007, 08:28 PM
Dragon Man,

Isn't that the same thing?

and also, you could do something like this:

<body>
<?php
$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 />
<?=$style?>
</body>


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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum