Php Tutorial 2 – Hello World Program

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.

 

Php Tutorial 1 – Setting up localhost

Hi everyone I’m starting with the tutorials of php here in a series, hope it help you guys, stay updates for a series of php tutorials.

As you know php is a server side scripting language, it is mainly used to develop websites and web-applications. Since it is a server side scripting language you need a server to run your php files, for this there are two options i.e either you get your web hosting account or setup your own server. I find setting up your server is a better option so here I will  tell you how to install it, I use WAMP server which automatically configures php, mysql, apache and phpmyadmin. Just click on the link below to download wamp server:

http://www.wampserver.com/en/download.php

download 32bit version or 64bit according to your requirement.

After installing you will get a shortcut on your desktop, start it by double clicking it you will get a wamp icon in your taskbar.

Click on that icon to get menu…

Wamp menu

>localhost – it will open the address of localhost in your web browser.

>phpmyadmin – this is a installed alias which will help you manage your databases.

>www directory – this is the directory where you will place you php files/projects to run.

>apache – manages apache extensions.

>php – manages php extensions.

>mysql – manages mysql extensions.

 

That was all about installing wamp server i.e setting up a localhost.

Next post will we a very simple post just telling you about a hello world program in php… till then install php… :)