Up until recently, scripting on the internet was something which very few people even attempted, let alone mastered. Recently though, more and more people have been building their own websites and scripting languages have become more important. Because of this, scripting languages are becoming easier to learn and PHP is one of the easiest and most powerful yet.
What Is PHP?
PHP stands for Hypertext Preprocessor and is a server-side scripting language (but can be used from a command line interface or in standalone graphical applications). This means that the script is run on your web server, not on the user's browser, so you do not need to worry about compatibility issues. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in.
The goal of the language is to allow web developers to write dynamically generated pages quickly. PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.) .PHP is an open source software (OSS) .PHP is free to download and use. PHP is relatively new (compared to languages such as Perl (CGI) and Java) but is quickly becoming one of the most popular scripting languages on the internet. PHP files may contain text, HTML tags and scripts.PHP files are returned to the browser as plain HTML.PHP files have a file extension of ".php", ".php3", or ".phtml"
The main implementation is produced by "The PHP Group" and released under the PHP License. It is considered to be free software by the Free Software Foundation.
PHP Advantages
The PHP offers a number of advantages to developers.
PHP runs on different platforms (Windows, Linux, Unix, etc.)
PHP is compatible with almost all servers used today (Apache, IIS, etc.)
PHP is FREE to download from the official PHP resource: www.php.net
PHP is easy to learn and runs efficiently on the server side
Reduce the time to create large websites.
Create a customized user experience for visitors based on information that you have gathered from them.
Open up thousands of possibilities for online tools.
Allow creation of shopping carts for e-commerce websites.
Where to Start?
Download PHP: Download PHP for free here: http://www.php.net/downloads.php
Download MySQL Database: Download MySQL for free here: http://www.mysql.com/downloads/index.html
Download Apache Server: Download Apache for free here: http://httpd.apache.org/download.cgi
Declaring PHP
PHP scripts are always enclosed in between two PHP tags. This tells your server to parse the information between them as PHP.
The three different forms are as follows :
1. PHP Code In Here
?>
2. PHP Code In Here
php?>
3.
PHP Code In Here
All of these work in exactly the same but one must remember, though, to start and end your code with the same tag (you can't start with for example).
Below, we have an example of a simple PHP script which sends the text "Hello World" to the browser:
//This is a comment
/*This is
a comment
block.*/
echo "Hello World";
?>
Each code line in PHP must end with a semicolon. The semicolon is a separator and is used to distinguish one set of instructions from another. In PHP, we use // to make a single-line comment or /* and */ to make a large comment block.
There are two basic statements to output text with PHP: echo and print. In the example above we have used the echo statement to output the text "Hello World".
Variables in PHP
A variable are used for storing a values, like text strings, numbers or arrays.When a variable is set it can be used over and over again in your script.All variables in PHP start with a $ sign symbol.The correct way of setting a variable in PHP:
$var_name = value;
In PHP a variable does not need to be declared before being set.In the example above, you see that you do not have to tell PHP which data type the variable is.PHP automatically converts the variable to the correct data type, depending on how they are set.
Expresions in PHP
Following is the code for expressions in PHP:
Finishing and Testing Your Script
Now save your script as phpinfo.php and upload it to your server in the normal way. Now, using your browser, go to the URL of the script. If it has worked (and if PHP is installed on your server) you should get a huge page full of the information about PHP on your server.
If your script doesn't work and a blank page displays, you have either mistyped your code or your server does not support this function (although I have not yet found a server that does not). If, instead of a page being displayed, you are prompted to download the file, PHP is not installed on your server and you should either search for a new web host or ask your current host to install PHP.