What is PHP?
Saturday, October 11th, 2008 by Peter Zhang
Nowadays, most websites are created out of PHP. Why? Simply because it is flexible. It can integrate very nicely into other programming languages and databases such as HTML, Javascript, Ajax, MySQL, etc. Also, it is absolutely free to use!
PHP stands for PHP: Hypertext Preprocessor (It doesn’t really make sense, I know.. ). The latest stable version is 5.2.6 (as of the time this post was posted. In this article, I am going to post a short introduction of PHP. If you are already a PHP guru, I suggest you to skip this =)
To use PHP, you will need a server or a hosting space on the internet. If you don’t have any of them, you may also install Apache and PHP to set up a server on your own PC (for your own use, too), but it is often times very complicated, so I’d suggest you to download XAMPP, a software that has all you need if you want to try out PHP. After you install XAMPP and make sure it’s running, you may go to http://localhost/ and look at what you have now!
Grab yourself a copy of Notepad++, or a professional coding program such as Dreamweaver or ZendStudio (or, just regular notepad will be fine), then you may start coding PHP now!
A small reminder: Coding for PHP requires some basic knowledge of HTML.
PHP codes usually begins like this:
<?phpand ends with this:
?>PHP codes are to be put between those two tags. You can usually put it in everywhere on a webpage. Let’s say, it can appear in the title:
<title><?php echo "Put your title here"; ?></title> // So that the title of the webpage becomes Put your title here
Or it can also appear in the main content:
<p>My name is: <?php echo $name; ?></p> // So that the it will show "My name is: " and then the value of the variable name
Notice how I used the function “echo” in the code above. “echo” is similar, if not the same, as “print” in other languages. It displays whatever in the quotes, or the value of the variable given.
Usually tutorials out there begins with taeching you how to produce a line of “Hello, World!”, and this isn’t an exception. Let’s start. Type the following code into whatever software you are using to code (Notepad, Notepad++, or others) and then save it as index.php. Then, either upload to your webserver or save it at C:/xampp/htdocs (if you have XAMPP installed instead of having a webserver. Make sure your XAMPP is turned on)
<?php echo "Hello, World!"; ?>
Now go to your webserver address or point yourself to http://localhost/ to see what will appear. If “Hello, World!” (without quotes) appeared, then, congratulations!
Now we might want to try something more advanced than this. Clear what you have in index.php, and put the following code:
<?php $hello = "Hello, World!"; echo $hello; ?>
Now do the same thing as you did to the last file, and see if there is any difference on the output. In the code above, the string (meaning, a bunch of texts) “Hello, World!” (without the quotes) is stored in the variable $hello. Then, whatever stored in the $hello is then echo‘d out.
At last, I would like to mention about the connector “.” (the period symbol). Try reading the following code and you will hopefully know what it does:
<?php $hello = "Hello"; echo $hello . ", World!"; ?>
Yup, the output of the above code is “Hello, World!”. The “.” is placed there to connect between the variable $hello and the string “, World” (without quotes)
This is it for the basic introduction of PHP. Come back to TechCube to check out more PHP tutorials!
Also, we believe that the best way to learn a coding language is through reading them and doing them yourselves. This is my challenge to y’all today: Create a table that has the columns “Name, Age, Gender, Website” on the left and each in its own row, then use php to echo out the corresponding information in its corresponding row with variables. When you are done, send it to me and I’ll grade it… just kidding. You don’t need to do that, but if you have any questions at all, just feel free to ask. We are all here to help!






