Website Programming

The Difference between HTML and PHP
The Difference between HTML and PHP

The Difference

this is a normal HTML(index.html):
<html>
<head>

</head>
<body>
<!-- Page Content -->
</body>
</html>
this is a normal PHP(index.php):
<?php

/**
* Page Content
*/

echo "some text here";

?>

PHP with HTML

Using PHP and HTML on the same page
There are two ways to use HTML on your PHP page.
  1. put the HTML outside of your PHP tags.
  2. using PRINT or ECHO
And one way to use PHP on your HTML page
  1. using PHP Template Engine e.g (Rain TPL)

example #1

put the HTML outside of your PHP tags.
<html> 
<title>example #1</title>
<body>
<h1>My Example</h1>
<?php

//your php code here

?>
<b>Here is some more HTML</b>
<?php

//more php code

?>
</body>
</html>

example #2

using PRINT or ECHO
<?php 

Echo "<html>";
Echo "<title>HTML with PHP</title>";
Echo "<b>My Example</b>";

//your php code here

Print "<i>Print works too!</i>";
?>

example #3

use PHP on your HTML page (PHP Template Engine)
(tpl.htm)
<html> 
<title>{$title}</title>
<body>

<h1>My Example</h1>
<b>{$text}</b>

</body>
</html>
(index.php)
<?php

$tpl->assign( "title", 'Hello World!' );
$tpl->assign( "text", 'Here is some more text!' );

echo $tpl->draw( 'tpl' );
?>
in: » Website Programming | Posted on Sep 4th, 2009 | views 7,099
About the author
i'm moustafa from egypt i love doing one thing 'web programming & designing', This year I've got 19 years old and i'm in the english College of management (in Business Administration part soon)