Posts Tagged PHP tags

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:

Share This Post

, , , , , ,

3 Comments

All About PHP

 

A B C Of PHP

  • PHP stands for Hypertext Preprocessor.
  • It’s a server side scripting language, like ASP.NET, JSP, Perl etc.
  • It is an interpretted language, means no need for compiling PHP programs before executing them.

Current Version

Current version while writing up this post is PHP 5.3.2.

Basic Funda Of PHP

Step1: Assume you open your web browser and type in any URL (let it be ultimatechange.co.cc). So now your web browser will send a request to the corresponding server (of this URL).

Step2: The web server on the other hand receive this request. It spots out that this URL ends with “.php” extension and so it send this request to the PHP interpreter which is present in the server only (consider the interpreter to be a part of server for now).

Step3: The PHP interpreter accepts the request send to it by the server. It then starts executing whatever PHP-tags are associated with that particular request (hope you have little idea about tags, if not then consider it to be as some code for now).

As execution is completed the response (result) is sent back to your browser. And finally what you get to see is ultimatechange.co.cc blog or whatever you have requested for.

What Makes It Special? 

Server Side Player: As discussed above PHP code is processed at the server side and not on client’s browser. Now this may sound you very normal thing, but even this little thing make a big difference. How?  Actually what happens is for all client side scripting languages(yes the one which are executed at your end) a complex logic is required for providing browser specifications. But with server side  scripting like PHP, anyone can easily write any program irrespective of client’s browser specifications.

Source Code Privacy: Yeah that’s another remarkable feature of PHP. And the credit for this again goes to server side scripting only. As all the PHP-tags are processed at the server side and only the result is send to the client, thus hardly you can see what’s the source code of the webpage is.

Requirements

Generally WAMP server is used when you want to try out your hands with PHP on windows. This WAMP server basically comprises of 4 components Windows, Apache, MySQL, PHP.

Now you might be amazed by reading out all these components, some of us will say when we can easily write out this PHP at notepad then why we will require all this things? So to answer your this query i want to drag your attention back to “Funda of PHP“, over their i told you that you client working on your system, request server which passes ahead the same to interpreter and so on.. So now considering you as a beginner to this language, i will recommend you to first practise out your PHP scripts on your system only. And once you have enough practice with it, then definately you can move on by simply writng PHP in notepad and then uploading files on FTP sever.

So for building and then testing all your PHP scripts locally on your machine, requires a specific environment comprises of:

  • An operating system where client work and a server environment(usually linux).
  • A webserver (usually apache on linux, while IIS on windows).
  • PHP interpreter to process all PHP codes.
  • Database (MySQL) to hold all data.

And that’s the reason why we choose WAMP server( for windows) or LAMP server (for linux).

Blog Widget by LinkWithinShare This Post

, , , , , , , , , ,

2 Comments

This site is protected by WP-CopyRightPro