PHP is a script on the server-side used for the creation of Static or Dynamic Web sites or Web applications. PHP is a pre-processor for hypertext, which used to stand for home pages. The software used to build web applications is an open-source, server-side scripting language. We say a program designed for automated work by writing a script-based language (code lines). It is suitable for the output and construction of dynamic web pages for web applications, e-commerce applications, and database applications. PHP can be inserted into HTML.
Whenever you type in a URL or request by clicking on any link (which again is nothing but indirectly supplying an URL,) the request is forwarded by your web browser (Firefox, Chrome, etc.) over the internet to a ‘server’. Now this server is where all the pages you code for are actually stored. Also, all the user accounts will obviously be present on the server. Now think about this: applications like Facebook, emails, etc., will have lots of user accounts, right? So managing such data is a little tricky. Hence computer programmers have come up with something called “databases”. These help in efficiently handling (usually large amounts of) data, especially when it’s something that can be tabulated.
ADVERTISEMENT Popular Course in this category PHP DEVELOPER - Specialization | 8 Course Series | 3 Mock TestsStart Your Free Software Development Course
Web development, programming languages, Software testing & others
So, when the request hits the server, the server processes the requests and responds with the data (as a plane response or embedded inside a webpage). For these purposes, it is used. Basically, it is a server-side scripting language. Currently, Version PHP7 is the latest version.
Following is a simple example of this Script inside an HTML page.
See how the PHP code is embedded in the HTML code to print the sentence Hi, Welcome to PHP in the body. The web server can be configured to process all the HTML files with PHP.
With this, we can:
There are three main fields where these scripts are used:
Given below shows working with PHP:
Embed the code enclosed within and whatever is inside this will be treated to a PHP code by the interpreter.
The code would look like this.
It supports eight primitive data types.
Four scalar types namely,
Two compound or derived datatypes.
Two special types, namely.
This is how one can dynamically create a variable and use it in this.
An array in PHP is an ordered map that maps keys to corresponding values. It is transformed in so many ways that one can use it as a real array, list (a heterogeneous array or as a vector), hash tables or dictionaries, collection, etc. Of course, in PHP, also like any other programming language, the arrays are zero-indexed.
This is how one can create and access arrays in this.
It comes with several predefined variables, which are as follows:
The following snippet shows the way to deal with if-else statements.
It has both for loop and do-while loop whose syntax goes like this.
This is a ‘for’ loop.
This is ‘for each’ loop.
This is a do-while loop.
We also have switch statements which help us do decision making based on fixed choices of values.
The below code shows how to use it.
In order to modularize the program and also to have the code re-usability, we can write functions in PHP. Every function will have a definition with a set of parameters defined along with a return value.
The following code snippet shows how one can write a function in this.
It supports dealing with Cookies. Cookies are the mechanism for storing data inside the web browsers for quicker responses and tracking of returning users. One can use the set-cookie () function to set cookies in PHP.
The below code shows it.
A GET method is the one in which the request variables are embedded in the request URL and forwarded to a server. We use the $_GET global variable to receive and access the GET request variables. The data from the web page is submitted to the server script via a form in the web page. So, the form action must have the link to the server script that will be handling the form data.
The following snippet will show how to access the GET variables in PHP.
In a POST HTTP request, the data is wrapped inside the body of the request and sent to the server. To access the variables sent over a POST request, we use the global variable $_POST.
The following code snippet will show how to handle the POST request.
There is still more in PHP than these, which you can explore with these strong basics.
Following are the advantages as follow:
Well, ask after 3 years, and the answer will still be ‘Yes’.
So yes, the relevance of this is going to remain intact.
Career Growth in this Technology
The above is the detailed content of What is PHP. For more information, please follow other related articles on the PHP Chinese website!