Tutorials Home Scripts Home

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' );
?>

Category: Website Programming | Views: 2,878 | on: September 04, 2009 | by: jooria
Enjoyed the article? Subscribe and get the new Tutorials

Enter your email address:

Last 1 Responses

Comment form

  1. Web Design Company About 5 months ago
    Very well put! HTML is very simple and you can probably learn it in a couple of days if not faster.

Leave a Comment

Comment form