1. Computing

Discuss in my forum

Formatting Your PHP

Making Your PHP Pretty

By , About.com Guide

So you've gone though some of the tutorials, and you can make some nifty things in PHP. But the problem is, they all look like plain text. How do you jazz them up?

Formatting with PHP actually isn't done with PHP, it's done with HTML. You can do this in two ways. You can add the HTML inside of the PHP... or you can add the PHP inside of the HTML. Either way, make sure your file is saved as a .php or another file type that is allowed to execute PHP on your server.

Let's do something simple.... let's make our text red!

HTML inside PHP

 <?php
 echo "<font color=#ff0000>Hello World!</font>";
 ?> 
Notice how we include the HTML code right inside of the echo.

PHP inside HTML

 <font color=#ff0000>
 <?php echo "Hello World!"; ?>
 </font> 
In the second example we simply insert a line of PHP inside our HTML. Although here it is only a line to make the text red, this could be inside a fully formatted HTML page, to get any look you want.
Related Video
Basic PHP Syntax
Using PHP With HTML
  1. About.com
  2. Computing
  3. PHP / MySQL
  4. Learn PHP
  5. Format Your PHP - Make PHP Pages Pretty

©2013 About.com. All rights reserved.