What is PHP?
PHP stands for PHP: Hypertext Preprocessor. PHP is mostly used and it is a scripting server side scripting language. The scripts of PHP always executes on the server. You can download PHP with no cost means free available to download. Inside PHP file, you can use HTML, java script, Jquery, Ajax etc.
A php file contains HTML, jscript, jquery etc. PHP always executes on server means for executing php file, one server is required. A file which has extension .php or .php3 is known as php file.
Why use PHP?
Php provides many platforms to run means php runs on several platforms like windows, Mac, Ubuntu etc. PHP provides the compatibility with most of web servers such as wamp, xampp, IIS, Apache etc. PHP is free to download from its official site www.php.net.
Requirement to learn PHP:
You should have knowledge of HTML, CSS, Java script etc. then you can easily learn the PHP in easiest way.
Tools to run the PHP:
- Web browser is required to execute the php file.
- Your system should have a web server like Apache, xampp, wamp etc.
- These all servers is free available, you can download form official sites.
- An editor is needed to write the HTML.
Choose Browser: you can choose one browser such as
- Mozilla Firefox
- Internet Explorer
- Google Chrome
Choose Server: you can choose one of server such as
Choose Editor for PHP:
Editor helps you to write the PHP code in an efficient manner and provides the proper help and hints when you use some tag then editor provides you the options to choose the attributes and also values for that particular tag which you apply for the formatting. There are various editors are available in the market but most popular are Notepad++ and Dreamviewer.
There are several editors for writing the PHP such editors which are as follows:
- Dream viewer
Syntax of PHP: the php syntax tells you how php starts in file. The syntax is as follows:
PHP code always starts with <?php and ends with ?> this sign. A php file contains any number of php blocks to make the separate portion, some time we needed separate portion.
Where to save the PHP file: In XAMPP server, you have to save the file with .php extension in “C:\xampp\htdocs” and inside htdocs you can make your own folder then save file in folder. It is better to save programs in folder shown in below figure:
Here we have made a folder named PHPDemo. Now save the programs in this folder.
How to run PHP file on server? : First you have to start the server and type localhost in the URL and hit enter. Now localhost will be open and now you have to give the path of your file and hit enter. This process is in the following diagram:
How to print message in PHP? : A function echo is used to print the statement in the PHP. Inside double quotes you have to give the message and this also prints the variables values even you have given variable inside the double quotes. The syntax is as follows:
Variables and data type in PHP: variables in php is declared with $ sign such as $a; and there is no specified data type in PHP as C or C++. In PHP, the value of variable defines the type of variable. The example is as follows:
Inside this we have declared variable named and also initialized with value 10 means this value determines the data type of this variable means this variable is of integer type. In PHP, one variable can be declared many times. Thus you can say that PHP is loosely coupled server side scripting. The output of program shown in above diagram is as follows:
How to use OOPs in PHP: PHP provides the features of the object oriented programming language such as class, object, inheritance, polymorphism etc. In PHP, you can declare a class using the following syntax:
In this syntax, class is a keyword and className is name of class. You can also use the function inside the class. The syntax is as follow to make a function inside the class:
In this syntax, function is a keyword and you have to give the name of function and you can also give the arguments and provide the body for it. To call the function, you must create object of the class then you are able to call the function. The syntax to create object and call function using function as follows:
The example of function in class as follows:
$a = 10;
echo “the value of a is : $a”;
$ob = new A();
The output of this file is as follows:
|the value of a is : 10|
How to use HTML is PHP? : You can use HTML in PHP. You can understand this using the following example:
echo “<p> HTML mixed in PHP”;
You can mix the HTML using the echo function; you have to write the tags inside echo and another ways to use HTML in PHP file is as follows:
Message using HTML
echo “<br> Message using PHP”;
PHP provides various features as follows:
|1. Object oriented programming|
2. Exception handling
3. Special type of array called associative array
4. Validation programming
6. Robust security
7. Connectivity with MySql
8. Connectivity with more database
9. You can connect android apps with PHP
10. The popular example of PHP is Facebook
To know more about PHP visit http://www.eitworld.com/php-tutorial/