This is a work in progress! I’m writing this book out in the open. It’s messy, unedited, and extemely unfinished. You’re welcome to take a look, and if you have any feedback I’d love to hear from you.
Introduction
Chapter 1In the mid 1990s, when the web was still new, Rasmus Lerdorf created Personal Home Page Tools, a collection of utilities written in C that he ran on his personal website. These were tools that let him accept data submitted with forms and then display that data on his pages—features that have never been achieveable with HTML alone. Lerdorf didn’t intend for PHP to become a complete standalone programming language, but people loved what he was working on and a language sprung up around it nonetheless. After a few iterations, Personal Home Page Tools eventually became known as just PHP, cleverly standing for PHP: Hypertext Preprocessor.
PHP was born out of the simple desire to add another dimension to the already amazing world of HTML and web pages, making it possible to go beyond the inherently static nature of the medium and to build truly dynamic pages. Pages where data can be added or changed without having to edit your HTML. Pages that make the web feel like more of a two-way medium. It’s exciting stuff!
It may be just a programming language, but using PHP can feel magical at times. There’s something truly special about pulling things in from different places, transforming them, and displaying them on a page, using nothing but relatively simple instructions. It’s a lot of fun, too.
About this book
This book will teach you how PHP works and will guide you through writing a simple program using the language. It focuses on using the elegant simplicity of PHP alone, so you won’t find anything about Laravel or other frameworks here. Similarly, you won’t see anything about MySQL or MariaDB, because we don’t need them for what we’re building here (and you may never need them for anything you build!). There are plenty of folks out there who believe that PHP is pointless without Laravel and MySQL, but I’m not one of them.
A note about coding norms
With PHP, there are many different approaches you can take to achieve a desired outcome. Some approaches might have more advantages than others, particularly in terms of efficiency, ease of maintenance, or other factors. That said, I don’t really buy into the idea that there is an inherently right or wrong way to tackle any given problem. If the solution works, and the author is happy with their approach, that’s pretty much all that matters. As you learn PHP and use it more, you’ll inevitably encounter people who will try to tell you that you’re doing it wrong even though your code works just fine. You can safely ignore those people.
And with that out of the way, we can move on to getting things set up for development.