Simple PHP Tutorials - Lesson 1: What is PHP?

I’ve decided that the only real knowledge that I have about anything is PHP. So, I’ve decided to make some tutorials that I will try and stay on top of. I’ve done much better with updating this blog then I ever have before, so I think this should go well. So, here is the first tutorial in hopefully a string of many.

What is PHP? PHP is a server-side scripting language. That means that PHP scripts are executed on the server before they are sent to your computer. Most people have heard of JavaScript. It is a different kind of scripting language where the scripts are run on your computer rather than on the server.

What is PHP used for? PHP was built to allow developers to create dynamically built web pages. This website is an example of a webpage built with PHP. It allows me to dynamically change the content of the website without having to manually change the HTML of the page. For example, see the categories on the right side. Those categories are stored in a database. When the webpage loads, PHP grabs the categories from the database and builds the HTML content on the server. The HTML is then sent to your computer where the web browser, probably Internet Explorer or Firefox, reads it and displays it to you.

Okay, so now I’m going to show you the first program. In order to run a PHP program, you must on a server that has PHP. Setting that up is beyond the scope of these tutorials. Here it is, the standard “Hello World” program:

<?php

echo “Hello World!”;

?>

Take that code and paste it in to your favorite text editor. Save the file as helloworld.php or anything you want with the extension .php at the end. Now copy it to your web accessible directory and type in the url (e.g. http://www.morrise.com/helloworld.php).

Let’s take a look at this code. First we have the <?php and the ?>. Those tell the server that we want to use PHP. Anything that we put between those brackets will be interpreted as PHP. Then we have the echo “Hello World!” line. echo is just another term for print. The quotation marks tells PHP that we have text, so echo “Hello World!” prints out the text “Hello World” (without the quotation marks or course).

There you have it, you’re first PHP program. I hope you have enjoyed this simple tutorial and we will see you next time.

Feel free to ask questions in the comments section. I will try to be prompt at answering them.

Leave a Reply