1. Home
  2. Computing & Technology
  3. PHP / MySQL

PHP with HTML
Using PHP and HTML on the same page

By Angela Bradley, About.com

There are two ways to use HTML on your PHP page. The first way is to put the HTML outside of your PHP tags. You can even put it in the middle if you close and reopen the <?php -and- ?> tags. Here is an example of putting the HTML outside of the tags:
<html>
<title>HTML with PHP</title>
<body>
<h1>My Example</h1>

<?php
//your php code here
?>

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

<?php
//more php code
?>


</body>
</html>
As you can see you can use any HTML you want without doing anything special or extra in your .php file, as long as it is outside of the PHP tags.

The second way to use HTML with PHP is by using PRINT or ECHO. By using this method you can include the HTML inside of the PHP tags. This is a nice quick method if you only have a line or so to do. Here is an example:

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

//your php code here

Print "<i>Print works too!</i>";
?>
Using one or both of these methods you can easily embed HTML code in your PHP pages, to give them a nicer more formatted look, and make them more user friendly.
More PHP / MySQL Quick Tips
Explore PHP / MySQL
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Learn PHP
  5. PHP in HTML - HTML inside PHP - PHP embed HTML

©2009 About.com, a part of The New York Times Company.

All rights reserved.