Saturday, 9 February 2013

Online PHP Programming Tutorial: Learn Basics of PHP Scripting With Simple PHP Code and Examples (Part 1)

Online PHP Programming Tutorial: Learn Basics of PHP Scripting With Simple PHP Code and Examples (Part 1)

Introduction to PHP: PHP stands for Hypertext Preprocessor. PHP is a server scripting language and is used for creating dynamic web pages. PHP is an open source scripting language. We will discuss some similarities and differences between PHP and ASP.NET later in this tutorial.

Learning PHP Programming

Learning PHP programming and development is very easy. PHP has very simple syntax. In this online PHP tutorial, we will learn PHP step by step by simple PHP examples using short and simple PHP scripts and codes. Lets start learning PHP scripting now:

1. Simple PHP Code Snippet

echo "Lets learn PHP Programming!";

Some basic things to note in PHP scripting:

1. A PHP script starts with <?php and ends with ?>.
2. Each code line in PHP must end with a semicolon.
3. PHP files have a default file extension of ".php".
4. In PHP, there are two basic statements to output text in the browser: echo and print.

2. Comments in PHP Programming

//PHP Single Line Comments
Multi Line Comments

3. Rules for PHP Variables

1. PHP variable starts with the $ sign, followed by the name of the variable
2. PHP variable name must begin with a letter or the underscore character
3. PHP variable name only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
4. PHP variable name should not contain spaces
5. PHP variable names are case sensitive ($y and $Y are two different variables)
6. PHP has no command for declaring a variable
7. PHP variables can be local, global and static
8. PHP string variable is used to store and manipulate text. When you assign a text value to a variable, remember to put single or double quotes around the value.

PHP Variables Example

echo $z;

4. PHP is a Loosely Typed Language

You don't have to declare data type the variable in PHP. PHP automatically converts the variable to the correct data type, depending on its value. In a strongly typed programming language, we will have to declare datatype of the variable before using it.

Consider the following simple PHP example:

$txt="PHP is a loosely typed language";

After the execution of the statements above, the variable txt will hold the value Hello world!, and the variable x will hold the value 5. When you assign a text value to a variable, put quotes around the value.

5. Types of Array in PHP

In PHP, there are three types of arrays:

Indexed arrays - Arrays with numeric index
Associative arrays - Arrays with named keys - Associative arrays are arrays that use named keys that you assign to them.
Multidimensional arrays - Arrays containing one or more arrays

Similarity and Differences between PHP and ASP.NET

PHP is a strong competitor of Microsoft ASP.NET. PHP goes ahead of ASP.NET in some case like:

1. PHP runs on different platforms likeWindows, Linux, Unix, Mac OS X, etc. ASP.NET on the other hand, only runs fine on Windows.

2. PHP is compatible with both Apache, IIS while ASP.NET has compatibility only with IIS. You can configure ASP.NET to run on Apache, but that is cumbersome.

3. PHP is open source and free. No license required for using PHP for commercial purposes.
Similarity between ASP.NET and PHP

1. Both ASP.NET and PHP are used for dynamic webpage development.

2. Both ASP.NET and PHP are easy to learn and understand.

3. Both ASP.NET and PHP have support for a wide range of databases.

4. Both ASP.NET and PHP have large online developer forums to support web development. For example, you will find a large community of ASP.NET and PHP developers on

No comments:

Post a Comment