In this tutorial, I will explain basic about php listed here:
- History of PHP
- What is PHP
- Why PHP?
- What can PHP do?
- How PHP Works?
Let’s start from the first topic:
History of PHP:
In 1994, Rasmus Lerdorf developed PHP for personal use and then in 1995, he has released the first version of PHP with the name of “Personal Homepage”. In 1997,PHP was being used by more than 50,000 sites.
What is PHP?
PHP is an ‘OPEN SOURCE TECHNOLOGY’ which means the source is openly available.There is no requirement to pay for it.
Any technology(software) is open source,it is free of cost but if it is free of cost, it does not mean it is an open source technology.
PHP is a recursive acronym of “Hypertext PreProcessor” because it preprocesses the hypertext before displaying to the client.
PHP is a combination of C and C++. PHP is written in both C and C++.As we know C is a “Procedural language” which support procedure(function) whereas C++ is an “Object Oriented Language”.
There is mainly 2 reasons to use PHP and here I am going to explain both the reasons:
Programmer’s Point of view: PHP has shorter learning curve means it doesn’t take much time to learn PHP.PHP is flexible,robust,compatible,stable,easy to use and cross-platform.
Business Point of view: If we see it from the business point of view,it is all about Money because PHP is open source.
PHP is mainly useful for web development.Web application support client-server architecture in which client sent the request to server and server serve the request sent by the client.The server is one machine which has operating system,Database server,web server,FTP server and Telnet server etc.
There is two type of programming languages
An interpreted language generates the .exe file from the source file after compilation
An interpreted language is one where the source file interpreted before generating output and it does not generate the .exe file.
PHP does not compile the file or generate .exe so we can say it is using Interpretation concept.The PHP interpreter (or parser) is the program that reads the PHP program file and executes the commands it understands
What can PHP do?
PHP is widely used general purpose scripting language that was originally designed for web development to produce dynamic web pages.
There are 3 main areas where PHP scripts are used:
1. Server Side Scripting
Server side scripting means a user can not view source code because the script was written at the server side.Every time a request is made to a Web server for a particular PHP file and the PHP interpreter must process the file and return the response to the web browser. PHP interpreter interprets a PHP program every time runs the program is known as a scripting language.
For Server Side Scripting we need:
2. Command line Scripting
With command line scripting,You can run PHP script without any server or browser.You only need PHP Parser to use this.
3. Desktop Application
PHP is probably not the very best language to create a Desktop application but you can develop with the use of PHP-GTK if you know very well and would like to use some advanced PHP features in your application. PHP-GTK is an extension used for graphical user interface.You can also write cross-platform application with this way.
In Short, PHP can convert the static website that content has to be changed by hand into a dynamic one that can display content based on any criteria.
How PHP Works?
Unlike HTML files, PHP files are routed through a special process that performs the PHP commands within the file before it is returned to the browser or client.
Let’s see the following image to understand the code:
PHP code must be enclosed within the PHP tags
Method 1: Short Open Tag
… ?> // Not Recommended
You can also use a short open tag as the PHP open tag if you enable the short_open_tags in php.ini file.However, this usage is not recommended. Method 2:
Each PHP sentence is terminated with semi-colon (;)
How to write COMMENTS In PHP?
Comments are a way to explain to other developers how you program code.When you write a code,It is good to use comment which will explain others or to you also that how your code works and why it is developed.
Now we will learn about how to write comments in PHP because You can write comments three different ways in PHP
Single line Comment :
Single line Shell Comment
Multi line comment : PHP provides a mechanism for detailed comments that is used for more than one line comment
This is the example of PHP comments:
Let’s see the example and understand how php syntax works:
Hello World'; ?>
In this example, you see that PHP code is embedded within PHP open tag . PHP then replaces that PHP code with its output.
Hello world! will be displayed in the Web browser. Interestingly, the single line statement enclosed within PHP tag.That’s it and It is your complete program.Isn’t it simple?
If you want to test configuration in PHP,insert the following code into a file and save the file as phpinfo.php
Run this file into a browser and you can see the list of configuration in PHP.
Literals in PHP
All strings must be enclosed in single quote or double quote
There are two differences between this two methods:
1. variables in a double-quoted string will be replaced with desired values whereas the single-quoted strings will be interpreted exactly as is.
2. A double quoted string recognizes all available delimiters whereas a single-quoted string recognizes only the delimiters “\\” and “\”.
Hello World'; ?> Hello World"; ?>
Numbers are not enclosed in quotes
Booleans can be directly written as true or false
Language Construct in PHP
Language construct can be used with or without brackets
Hello World'; print '
Hello World'; echo ('
Hello World'); print ('
Hello World'); ?>
Hope this tutorial will be useful to you. If you have any query,please write in comment section.