Ecapsulating HTML With PHP
creating hTools.php

This is the second half of the PHP lecture in the class Hypertext and It's Relations.

The main use of PHP is to write HTML. You can echo html to a web browser with the simple "echo" command. The line echo "<h1>Hello World</h1>"; sends the line <h1>Hello World</h1> to your browser. Your browser displays this string as:

Hello World

It is perfectly legitimate to write programs where you echo html to the screen as needed. I've found, however, that it is often beneficial to write functions that generate my html. This makes my code look cleaner, an gives me greater control over the formatting of my document.

For example, instead of printing a header by echoing the <h1> tag. I might find it beneficial to write a header function

The reason I like to do this is that it makes it easy to give all of my pages a common look and feel. It also makes my PHP look a lot cleaner...since I have fewer of those jagged HTML tags cluttering my code. Rather than explain the whys and wherefores, Let's just do it. I think that this is a really good process to learn fundamental PHP, and you will end up using all of this stuff in later programs.



index -- php lecture -- next
math, plusroot, search, rgreetings, sponsors