PHP Tutorial 2 - Hello World Program

Welcome back to the tutorials; this is Tutorial 2. Here we will start our programming in PHP. We will make various folders for various tutorials, so first make a Tutorial 2 folder in the www directory. We will do our programming in notepad or for your use you may use various user-friendly text editors like notepad++. PHP files have the .PHP extension; index.PHP is the file which is automatically executed in a folder, so make an index.PHP in the Tutorial 2 folder and type the following code into it.

In a PHP file we can add HTML, CSS, JavaScript or anyother language so we have PHP tags which tell the server that the lines inside these tags is PHP code; the opening tag for PHP is <?PHP and the closing tag is ?>.



Now let's write some code for a simple "Hello world" program:

<title>Innovation Escalator Tutorial</title>
echo "Hello World";

The Echo command is used for printing, and each and every statement is terminated by the use of a semicolon.

Use of variables, loop and if conditions in PHP:

if($i%2 == 0)
echo "Hello<br>";

The above PHP code prints hello only when the value of variable i is even. In PHP we just use a $ sign before a variable; moreover we don't need to define the variable type, it's up to you what data type you want to store, its a kind of flexibility.

This is all about the basics of PHP; wait for the next article for more. Until then if you have any queries you may post them.