Make your own free website on Tripod.com

Visit the Official PHP Website
Search this Site

PHP Programming Lesson 1e

By James N Hitz

Enter the "Here Document"

There is a PHP feature called the HERE document (Again I can't get to terms with why they called it the HERE document. What kinda' name is that anywayz?) HERE it is though! This HERE document allows the user to produce output without escaping. This is how it works:

You specify a start line. This is done by putting three less than signs and a LABEL. The LABEL is then followed by all your un-escaped (normal) text (read HTML), and then the LABEL again (This time without the three less thans). This LABEL can be anything you choose for as long it is NOT a PHP reserved word. In our example below we use the label OUTPUT:

   
print <<<OUTPUT
<html><head></head><body bgcolor="black" text="white">
<h2 align="right">Heading here
All your Other Unescaped Text comes here....
... and it can be veeeeeeeeeeeeeery many lines long.
OUTPUT;

This means "Print the following text until you encouter the LABEL (OUTPUT in our example)"

IMPORTANT

The terminating label (OUTPUT in this case) MUST start at the beginning of the line. It cannot be indented, not even by a single space. Sorry if you like indenting code but this has got to be the one and only one in the line. Come on I did not write PHP. I just teach it. (Ever heard of the self-proclaimed teacher).

Phew! This is a life saver. You don't have to struggle with escaping all those nerdy HTML tag attributes. Are we together pal? Let's sum our PHP knowledge so far...

<< Now What? | Lesson 1 Summary >>