I’ve been talking about PHP a lot recently, but so far I’ve said little about what it is and how it works.
So, What is PHP?
PHP files are a lot like HTML web pages, but also contain these PHP instructions or ‘scripts’. In normal Web browsing, the user requests a file by clicking on a link to it. If this is HTML it is sent directly to them, to be rendered on the screen as text and images by their browser. If it’s a PHP file however it is sent first to the PHP interpreter on the server. Here the scripts it contains are executed and the results – which are always HTML – inserted into the document where the script used to be. Now entirely HTML, it is sent to the user’s browser to be rendered in the usual manner.
So What Can They Do There, These Scripts?
In this way PHP can take requests from a website user, turn them into SQL or some other database query language, and format the results of the query as HTML to send back to the user’s browser where they can be displayed. As I mentioned in the previous post (and the one before that), this is a hugely powerful and flexible technique that can be used for untold purposes. While pages of search results would seem an obvious example, that’s just the nursery slopes. Systems as complex as Facebook are built in PHP. And systems that are good too.