Php Tutorial 2 – Hello World Program

By | August 10, 2011

Welcome back to the tutorial 2, here we will start our programming in php. We will make different folders for different tutorials, so first make a Tutorial 2 folder in www directory. We will do our programming in notepad or for your use you may use different user friendly text editors like notepad ++. Php files have .php extension, index.php is the file which is automatically executed in a folder, so make a index.php in Tutorial 2 folder and type the below code in .

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 are php codes, opening tag for php is <?php and closing tag is ?>

e.g.

<?php

……

code

……

?>

now lets code for a simple hello world program.

<html>

<head>

<title>Innovation Escalator Tutorial</title>

</head>

<body>

<?php

echo “Hello World”;

?>

</body>

</html>

echo command is used for printing, and each and every statement is terminated by a 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 its up to you what data type you want to store, its a kind of flexibility.

This is all about basic of php… wait for next. Till then if you have any queries you make post them.

 

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.