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.
- put the HTML outside of your PHP tags.
- using PRINT or ECHO
And one way to use PHP on your HTML page
- 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