1.2. Structure of a PHP Script

PHP is an embedded scripting language when used in Web pages. This means that PHP code is embedded in HTML code. You use HTML tags to enclose the PHP language that you embed in your HTML file — the same way that you would use other HTML tags. You create and edit Web pages containing PHP the same way that you create and edit regular HTML pages.

The PHP language statements are enclosed in PHP tags with the following form:

<?php      ?>

Sometimes you can use a shorter version of the PHP tags. You can try using <? and ?> without the php. If short tags are enabled, you can save a little typing. However, if you use short tags, your scripts won't run if they're moved to another Web host where PHP short tags are not activated.

PHP processes all statements between the two PHP tags. After the PHP section is processed, it's discarded. Or if the PHP statements produce output, the PHP section is replaced by the output. The browser doesn't see the PHP section — the browser sees only its output, if there is any. For more on this process, see the sidebar "How the Web server processes PHP files."

As an example, start with an HTML script that displays Hello World! in the browser window, shown in Listing 1-1. (It's a tradition that the first script you write in any language is the Hello World script. You might have written a Hello World script when you first learned HTML.) ...

Get PHP & MySQL® Web Development All-in-One Desk Reference for Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.