Using PHP

PHP requires software to run, whether it’s on the web server or on your computer. A good guide to installing this software (if you’re installing it on your computer, you’ll be installing a server as well) can be found from Christopher Heng.

PHP can be written in a simple text editor, as it is embedded in the HTML. As with JavaScript, we’ll give a brief example of how to create a sample page, one that offers a welcome message to the viewer. Within the body of a normal HTML page, you can write a PHP tag like this one:

<?php echo '<p>Hello Visitor!</p>'; ?>

If the PHP software is installed on your server correctly and if you saved the page with a file extension of .php and not .html, it will convert this tag to proper HTML for display in the browser, which ultimately renders it as “Hello Visitor!” Of course, you could have performed this task anyway, just using HTML. PHP’s true value lies in its more advanced functionality, which can be used to create interactivity. PHP, like ASP.NET, is often combined with databases. PHP can be used to communicate with a database, gather input or data from a user, and create an interactive experience from that. Of course, acquiring the knowledge to do this takes some practice and study, but PHP is a popular technology for this sort of interaction. Should you want to pursue PHP, we’ve provided a few resources below.

Note that PHP is a server-side technology. If you want .php files to work as designed on a web server, PHP must be installed on that server. Keep this in mind when you choose a web host for your website. Many hosts, but certainly not all, support PHP. Most will clearly state whether or not they support PHP.