A Beginner’s Guide To Php

A Beginner’s Guide To Php




PHP is officially known as PHP: HyperText Preprocessor. It is a server-side scripting language just like Active Server Pages (Asp), Java Server Pages (Jsp) and Cold Fusion (CF). It is usually written in an HTML context. Unlike an ordinary HTMLpage, Server doesn’t send php script directly to a client; instead, it is parsed by the PHP binary or module. HTML in the script is ignored, but PHPcode is interpreted and executed. PHP code in a script can query databases, create images, read and write files, talk to far away servers- the possibilities are endless. Finally the php code consequence and HTML is combined and output is send to the client.

PHP Installation on your computer In order to run php on your computer you must have following elements installed on it.

1. Web Server (IIS or Apache)

2. PHP

3. Mysql (optional)

Most websites advise you to install all elements manually but its just wastage of time. Visit http://www.wampserver.com and install latest version of WAMP it will automatically install php, apache and mysql on your computer with a single click. Its an open source software and very easy to use.

How to run php scripts

During installation WAMP creates a “www” directory in the installation folder. Save all your php scripts in it and then call it from your browser like this

“http://localhost/yourscriptname.php” where “yourscriptname” is the name of your php file.

First Script

Open your favorite text editor. Like HTML documents, PHP files are made up of plain text. You can create them with anytext editor, such as Notepad. However I advise you to use a specialized php editor. Macromedia Dreamweaver is the best php editor but its not free. You can find lots of good php editors at http://www.sourceforge.net

or simply Google it with keywords “free php editors”

Here is your first php script

1:

2: print “Hello World!”;

3: ?>

Save this script in www directory. Then call it from your browser like this

localhost/first.php

You will get following consequence;

Hello World

Remember : Always write your php code between opening and closing tags. Consider the following example.

Code goes here

?>

Adding Comments to PHP Code

A comment is text in a script that is ignored by the interpreter. Comments make your life lot more easier because Code that seems clear at the time of writing, can be extremely frustrating when you come to amend it six or tweleve months later. Adding comments saves time besides it makes it easier for other programmers to work with your code.

You can make comments in many ways

Single line comments begin with two forward slashes (/ /) or a single hash sign (#).

All text from either of these marks until either the end of the line or the PHP close tag is ignored.

// this is a comment # this is another comment

Multi line comments begin with a forward slash followed by an asterisk (/*) and end with an asterisk followed by a forward slash (*/).

/*

Add your text here.

Interpreter will not parse it.

*/




leave your comment

Top