Reader Level:
ARTICLE

PHP Tutorial 2 - Hello World Program

Posted by Shubham Saxena Articles | PHP 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
  • 4164

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 ?>.

e.g.

<?PHP
.......
code
.......
?>

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

<html>
<head>
<title>Innovation Escalator Tutorial</title>
</head>
<body>
<?PHP
echo "Hello World";
?>
</body>
</html>

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:

<?PHP
for($i=0;$i<10;$i++)
{
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.

COMMENT USING

Trending up