Chapter 2. PHP Meets HTML

With your first PHP script under your belt, you’ve made some real progress. But that PHP script might not have been what you expected. Most web developers don’t fall asleep at night dreaming of seeing this in a terminal window:

Hello there. So I hear you're learning to be a PHP programmer!
Why don't you type in your name for me:
Brett

Thanks, Brett, it's really nice to meet you.

Even less impressive than its complexity (or lack thereof) is the script’s format. It’s just plain text. There’s no formatting; in other words, no HTML.

In this chapter, you’re going to inject HTML into your scripts. No command-line prompts and boring text. By the time you’re through, your script will be speaking the language of the Web—HTML. In addition, you’ll see how PHP does one of its core tasks: respond to an HTML form.

Script or HTML?

Before you can start doing fancy party tricks with PHP, you’ve got to get over a bit of a conceptual hurdle. So far in your web programming journey, you’re probably used to thinking about the technologies you’ve learned in strict categories: HTML is markup, the structure of your page; CSS applies style to that structure; and JavaScript adds some interaction, with everything from alert boxes to validation, redirection, and widgets.

In the process, you probably also built some syntax categories. Your HTML is angle brackets, <title> and <head> and <ul>, and the like. CSS is curly braces and style keywords like p.warning and ...

Get PHP & MySQL: The Missing Manual, 2nd Edition 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.