Chapter 3. Introduction to PHP
In Chapter 1, I explained that PHP is the language that you use to make the server generate dynamic output—output that is potentially different each time a browser requests a page. In this chapter, you’ll start learning this simple but powerful language; it will be the topic of the following chapters up through Chapter 7.
In production, your web pages will be a combination of HTML, CSS, JavaScript, PHP, and SQL. Furthermore, each page can lead to other pages to provide users with ways to click through links and fill out forms.
We can avoid all that complexity while learning each language, though. Let’s focus, for now, on just writing PHP code and making sure that you get the output you expect—or at least that you understand the output you actually get!
Incorporating PHP Within HTML
By default, PHP documents end with the extension .php. When a web server encounters this extension in a requested file, it automatically passes it to the PHP processor. Of course, web servers are highly configurable, and some web developers choose to force files ending with .htm or .html to also get parsed by the PHP processor, usually because they want to hide their use of PHP.
Your PHP program is responsible for passing back a clean file suitable for display in a web browser. At its very simplest, a PHP document will output only HTML. To prove this, you can take any normal HTML document and save it as a PHP document (for example, saving index.html as index.php), and ...
Get Learning PHP, MySQL & JavaScript, 7th 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.