Papers Home visit my blog at http://prasannatechdotcom.blogspot.com Contact Us
 
  Your Ad Here
Your Ad Here
PHP Tutorial: Lesson - 1

This tutorial teaches about introduction and basics of PHP.

Expansion of PHP is PHP Hypertext Preprocessor. This is a server side scripting  language for creating dynamic web pages. The main task of PHP is similar to ASP or JSP or CGI/C or CGI/Perl. The script can be embedded in HTML document. Those who are familiar with perl or C can quickly adapt to PHP. In this tutorial, I will also give comparison to C where ever required.

     PHP is open source and can be downloaded free and use. Generally PHP is used along with MySQL, Linux and Apache. The combination is called LAMP. It can also run in IIS and can be used in multiple platforms. Most of the web hosting providers provide PHP, Linux/Windows and MySQL in their hosting packages. For learning purpose you can download combination software from www.xampp.org. The XAMPP package includes MySQL, Apache and PHP on various platforms. Individual packages can also be downloaded from http://www.php.net/downloads.php for PHP, http://www.mysql.com/downloads/index.html for MySQL and http://httpd.apache.org/download.cgi for Apache. Go through the installation procedure as per the installation documents of each package and configure these three to work together.

    When we are going through the lesson and with exercises, understand the samples or examples and upload the files into the server for verification and practice. Execute the script file in the server side to see the results in the browser.

     Now, Let us start with PHP scripting language. As we mentioned earlier, PHP code is written and uploaded in the server side. When a client sends the request to the web server, the server interprets the scripting file and returns the plan HTML file. Let us take a simple file which contains only HTML code and save the file as test.php

<html>
<body>
<h1>Hello World</h1>
</body>
</html

     Upload the file into server and enter the url. "Hello World" will be displayed as it is in H1 format.

     PHP scripting block starts with <?php and ends with ?>. This block can be placed anywhere in the file/document. Now let us write some simple php file with "Hello World".

<html>
<body>
<?php echo "Hello World"; ?>
</body>
</html

    Save the above code as test1.php. The third line is PHP code and started with <?php indicates that the code block is PHP code which also ends with ?>. The statement echo "Hello World" will output to the output stream and sent to the client. Each PHP statement should end with semi-colon. The file should be saved with extension as php to execute this in the server side. Let us do this exercise. Upload the file and enter the url in the browser. Have you seen the result?

The comments are similar to C and C++ styles. Both /* */ and // are acceptable. /* */ can be used for multiple line comment and // are used for single line comment.

//This is the beginning the php file
<html>
<body>
/*This is the multiple line comments.
   Multiple lines can be kept in thecomment.
   The code inside these comment lines will
   not be executed
*/
<?php echo "Hello World"; ?>
</body>
</html

Variables. In C/C++, variables should be declared with corresponding data type like int a for integer variable. But in PHP, the type of the variable will be set automatically based on the usage of the variable. In PHP, a variable should always start with $ as $variablename = value;

Example: $num = 10;
               $str = "Hello World";

Ofcourse you need to keep <?php and ?> at the begin and end of the PHP block

Rules for variable names are

  1. It should start with a letter or an underscore "_"
  2. It should only contain alpha-numeric character and underscrores(a-z, A-Z, 0-9 and _)
  3. It should not contain spaces

 In the next Lesson 2 we will discuss about string variable, operations on string, various string functions,  arithmetic, comparison and logical operators

Send your feedback to feedback@prasannatech.com with Subject: PHP Tutorial

 
  Your Ad Here
 Home Checkers  Checks(Jigsaw)   NetCheckers NetChineseCheckers  NetRummy WordScramble  SnakesLadders
 CardMemory Knight's Tour Tower of Hanoi  NetBackgammon  Network Morris Snakes  Nursery Tutor NetChess
Chat ftpClient NetTicTacToe Play Fupa Online Games     Links Papers
 
Your Ad Here

Software developed by me are freeware and you are not required to pay any fees. However, if you like and appreciate, you can show your support by making a donation. It will help me to continue to develop new software, maintain already developed software and this web site.

Copyright (C), All rights reserved-2008
No warranty or guarantee not limited to these are provided with above free software. Send your comments or feedback
to  feedback@prasannatech.com. For advertising contact advertise@prasannatech.com