Chapter 2. Generating HTML with PHP

In This Chapter

  • Creating your first PHP program

  • Using quotation marks

  • Working with variables PHP style

  • Interpolating variables into text

  • Creating heredocs

In PHP, you aren't actually printing anything to the user; you're building an HTML document that will be sent to the browser, which will interpret the HTML and then print that (the HTML) out to the user. Therefore, all your code gets interpreted twice; first on the server to generate the HTML and then on the user's machine to generate the output display.

If you've used XHTML, CSS, and JavaScript, you might have been frustrated because all of these environments run on the client, and you have no control of the client environment. You don't know what browser the user will have, and thus you don't know exactly how XHTML, CSS, and JavaScript will run there. When you program in PHP, you're working on a machine (the server) that you actually control. You know exactly what the server's capabilities are because (in many cases) you configured it yourself.

It's still not a perfect situation, though, because your PHP code will generate XHTML/CSS pages (sometimes even with JavaScript), and those pages still have to contend with the wide array of client environments.

Creating Your First PHP Program

The first program you ever write in any language is invariably the "Hello World!" program or some variant thereof. Follow these steps:

  1. Create a new PHP file in Aptana Studio.

    See Chapter 1 of this minibook for instructions ...

Get HTML, XHTML, and CSS 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.