1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.


Using PHP and HTML on the same page


Man's hand using touchpad on a laptop at home
Johnny Greig/E+/Getty Images
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:
 <title>HTML with PHP</title>
 <h1>My Example</h1>

 //your php code here

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

 //more php code

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:

 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.
Related Video
Using PHP With HTML
See More About
  1. About.com
  2. Technology
  3. PHP / MySQL
  4. Learn PHP
  5. How to Use HTML Inside PHP on the Same Page

©2014 About.com. All rights reserved.