Hi
I would like to know is there any way to work out the php code snippets in a html pages?
Means i would like to use php code in html pages will it work? if so how? Please tell me how?
THank You.
php in html?
Moderator: General Moderators
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
To put it very simplistically with an extension of .php (if your webserver recognises it) any php code enclosed in
<?php and ?> tags will be processed. Anything outside of those tags will be simply output as HTML.
Example:
You may see some examples where only the <? tag is used rather than <?php but this is to be avoided as it relies on certain server settings. Always use <?php.
Normally what you want (ok personal preference) is to try to process as much php as possible at the top of the file and only echo variables within your html. This makes things easier to read. Try to avoid the following:
as matching brackets are easily lost.
You may want to start looking at some tutorials on the web to get to grips with this.
<?php and ?> tags will be processed. Anything outside of those tags will be simply output as HTML.
Example:
Code: Select all
<?php
// my "business logic will go here
$myvar="Well Hello There this is a variable";
?>
<html>
<head>
</head>
<body>
<p>This HTML will be output</p>
<?php
echo "<p>This php echo will also be output</p>";
?>
<p>This HTML will be output</p>
<?php
echo "<p>{$myvar}</p>";
?>
</body>
</html>Normally what you want (ok personal preference) is to try to process as much php as possible at the top of the file and only echo variables within your html. This makes things easier to read. Try to avoid the following:
Code: Select all
<p>This is some starting text</p>
<?php
if ($somevar == "Eeek") {
?>
<p>This is shown if variable $somevar is set</p>
<?php
}
?>You may want to start looking at some tutorials on the web to get to grips with this.