1. Computing

Discuss in my forum

How to include your HTML in your PHP

By , About.com Guide

Although you can use PHP to do a lot of fun things, PHP itself wont let you create aesthetically pleasing sites. All of the stylizing of your PHP pages is still done with HTML. You can swap between PHP and HTML in the same file, or you can include the HTML inside your PHP. Here are some examples:

Let's say you wanted to write a sentence in bold letters, and that sentence contented a variable. In this first method we will switch between PHP and HTML.

<?php
$love = "cake"; ?>
<b>I love <?php echo $love ?></b>

In this second method we never turn PHP off, we just echo our HTML.

<?php
$love = "cake";
echo "<b>I love $love</b>"
?>

Both with give you the same result: I love cake

Depending on how much HTML and how much PHP you have in any given file, or your personal preference, you may choose one method or the other.

©2013 About.com. All rights reserved.