Basic Syntax

I l @ ve RuBoard

In order to create your first PHP page, you will start off exactly as you would if you were creating an HTML document from scratch.

There are two main differences between a standard HTML document and a PHP document. First, PHP scripts should be saved with the .php extension (e.g., index.php ). Second, you wrap your PHP code with the <?PHP and ?> tags to indicate what is PHP as opposed to what is HTML.

To create a new PHP script on your computer:

  1. Open a text editor such as SimpleText, WordPad, or whichever application you prefer.

  2. Choose File > New to create a new, blank document.

  3. Type <HTML> <HEAD> <TITLE>First PHP Script</TITLE> </HEAD> <BODY> (Script 1.1).

    Script 1.1. This is the most basic structure of an HTML document, with the PHP tags inserted into the body section. All PHP scripts must use some form of the PHP tags in order for the server to know what to process as PHP. Anything within those brackets gets treated as PHP, while everything outside of them gets sent to the browser as standard HTML.

    graphics/01sc01.gif

    You can put each element or element group on its own line to make it neater.

  4. Type <?PHP on its own line.

  5. Press Return to create a new line and then type ?>.

  6. Type </BODY></HTML>.

  7. Choose File > Save As. In the dialog box that appears, choose Text Only (or ASCII) for the format.

  8. Choose the location where you wish to save the script.

  9. Save the script as first.php.

Tip

Check with your ISP to learn which file extensions you can use for PHP documents. For this book you will use .php, although you may be able to use . phtml instead. Servers still running PHP version 3 commonly use .php3 as the default extension. A file extension tells the server how to treat the file: file.php will go through the PHP module, file.asp is processed as ASP, and file.html is a static HTML document.


Tip

You can also check with your ISP to se if short tags (using <? and ?> instead of <?PHP and ?> ) or ASP tags ( <% and %> ) are acceptable. Programs like Macromedia Dreamweaver can work better with PHP pages if you use ASP tags.


I l @ ve RuBoard


PHP for the World Wide Web (Visual QuickStart Guide)
PHP for the World Wide Web (Visual QuickStart Guide)
ISBN: 0201727870
EAN: 2147483647
Year: 2001
Pages: 116
Authors: Larry Ullman

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net