First PHP Script


So if you have downloaded the WAMP server and get it installed on your machine then now you are ready to make your debut in PHP scripts.

COMMON ONE’S

  • Syntax: Every php statement will follow a common pattern like this:-

<? php

—————

—————

?>

As Php interpreter will only read those instructions which are inside the “<——–?>” php tags.

  • Semicolon: Every of the php statement inside the php tags will end via a semicolon “;”.

{Exceptional case}: Whether to mark the end of a php statement with or without semicolon, is the common area of error. It’s not every time that you have to put a semicolon over there, exception do exists.

Example1:

<?php echo “case 1″ ?>

Example2:

<?php echo “case2″;  echo “semicolon present” ?>

So as you see in the above examples in case1 where a single statement exists you can omit putting semicolon, as this”?>” closing of php will automatically includes a semicolon. But while there are multiple statements as in case2, you can’t omit the semicolon.

  • Comment: As simple as in javascipt.

<? php

//for a single line statement

?>

 

<? php

/* for

multiple line

statements */

?>

 

Let’s Start:

So after having an idea about the Php scripts structure now you can easily write one for yourself.

Step1: Open any of the text editor(notepad or notepad++).

Step2: Write any simple script, how about displaying something on the webbrowser? :-

<?Php echo”welcome to php” ?>

Step3: Save this with a “.php” extension. And please remember if you are saving using notepad don’t forget to put double quotes while specifying the file name or otherwise you will land with a text file.

EXECUTE & VIEW

Step1: Install WAMP server:

As installation about to complete, it will ask you to specify your browser location.

So specify where your browser file is located:

Step2: Left click on the WAMP server icon on the taskbar. Remember it’s left click not the usual right one.

Step3: Click on “localhost”.

Something like this would appear on your browser.

Step4: Now you will have to create a folder at “c:\wamp\www\” or wherever you have installed wamp server (let the folder name ultimatechange).  Basically we create this folder for simple accessibilty, so that we can have a single location where all our projects can be stored and can be accesed as require.

And then simply drag and drop the PHP-file which you have created above at this location:- ”c:\wamp\www\ultimatechange”.

Step5: Now refresh your browser. And you will see the folder which you had created above.

So click over the new folder which you created and you will get:

Step6: Here you can see “script1.php” the file which you created is appeared, so click it to see the output of your first php script:

Blog Widget by LinkWithin

ADVERTISEMENT

  1. Looking for Php/java/css/html/javascript coaching? Contact now@9999942838. Only for Delhi,Gurgaon Region. Home tutors also available. For futher details: Email Us
  2. Studying at MDU? Crack the xam with best material(including notes,ppt's). For futher details: Email Us
  3. Looking for a presentation on any of the topic? Contact now@9999942838. For futher details: Email Us
Share This Post

, , , , , ,

  1. #1 by vinoth kumar on June 26, 2010 - 2:41 pm

    Nice tutorial
    i was struggling how to execute the php file in my wamp server
    the mistake i did is i saved the php file without double quotes so it landed as text document
    Thank you veryyy much

  2. #2 by Prabhjot Singh on June 27, 2010 - 6:05 am

    @Vinoth Kumar,
    I too faced lotz of problem, when i was a begineer to the php. So don’t worry, as you move ahead you would be able to tackle all the problems yourself.

    Keep playing with php scripts. Have a great time.
    Thanx for the comment.

(will not be published)

 


This site is protected by WP-CopyRightPro