Monday, 17 December 2012

PHP Basics - Writing First Script

In this post i am going to explain how to start writing your PHP scripts in your computer Using WAMP Server.

If you haven't install WAMP server click here to learn how to install.

To start writing scripts in PHP you need Text Editor or IDE.

There are so many Text Editiors available for windows like NotePad, NotePad++ etc.

And IDEs Like NetBeans for PHP, Eclipse for  PHP, Aptana Studios are open source softwares available for PHP.





You cal download and install IDEs from below links.

Eclipse PDT
NetBeans
Aptana

Or you can use text editors like NotePad.

Now You are all set to write your scripts, You have to save all your script files under document root folder to make it easier for webserver to read and execute them.

C:\wamp\www\  is the roor directory for WAMP server.

Now open your IDE / Text Editor and create a project/folder to write your script.

and create a PHP file "helloworld.php" in it, Every PHP script file must end up with .php extention, so that web server can be able to understand the type of file it should handle so that it can execute that file in a proper way.

Now open helloworld.php  and write
----------------------------------------------------------------------

<?php
       
       echo "Hello World";

?>

---------------------------------------------------------------------

The above script will simply prints Hello World  to the browser,

<?php  - tag is used to start PHP script, PHP interpreter will starts executing script when it finds this start tag.
?>        - tag is used to close PHP script , Interpreter will stop working here till it finds next start tag.
echo     - prints standard out put to browser, in our case it will just send text Hello World to browser.

Now open your browser and type localhost, You should find Your project/folder name on tha local host if you write scripts in the root directory.

click on it and open your helloworld.php file.

and you should be able to see text " Hello World " in your browser




No comments:

Post a Comment