Reader Level:

PHP Tutorial 2 - Hello World Program

By Shubham Saxena on July 16, 2012
This tutorial will guide you to a simple "Hello world" program in PHP; it will also show the use of loop and conditional statements in PHP.
  • 0
  • 0
  • 4396

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.

Shubham Saxena

I'm Shubham Saxena MVP (Oct'12 to Oct'13) at Mindcracker, Ex - Microsoft Student Partner, Software Engg at Accenture. I am here to write some interesting blogs and hope it helps you.


Trending up