PHP
12 BEST PHP Books (2021 Update)
PHP is a server-side scripting language used to develop static and dynamic websites or web...
PHP is a server side scripting language. that is used to develop Static websites or Dynamic websites or Web applications. PHP stands for Hypertext Pre-processor, that earlier stood for Personal Home Pages.
PHP scripts can only be interpreted on a server that has PHP installed.
The client computers accessing the PHP scripts require a web browser only.
A PHP file contains PHP tags and ends with the extension ".php".
In this tutorial, you will learn-
A scripting language is a language that interprets scripts at runtime. Scripts are usually embedded into other software environments.
The purpose of the scripts is usually to enhance the performance or perform routine tasks for an application.
Server side scripts are interpreted on the server while client side scripts are interpreted by the client application.
PHP is a server side script that is interpreted on the server while JavaScript is an example of a client side script that is interpreted by the client browser. Both PHP and JavaScript can be embedded into HTML pages.
| Programming language | Scripting language |
| Has all the features needed to develop complete applications. | Mostly used for routine tasks |
| The code has to be compiled before it can be executed | The code is usually executed without compiling |
| Does not need to be embedded into other languages | Is usually embedded into other software environments. |
PHP code may be embedded into HTML code, or it can be used in combination with various web template systems, web content management system and web frameworks.
The flowchart diagram shown below illustrates the basic architecture of a PHP web application and how the server handles the requests.
You have obviously heard of a number of programming languages out there; you may be wondering why we would want to use PHP as our poison for the web programming. Below are some of the compelling reasons.
In terms of market share, there are over 20 million websites and application on the internet developed using PHP scripting language.
This may be attributed to the points raised above;
The diagram below shows some of the popular sites that use PHP
ASP – Active Server Pages, JSP – Java Server Pages, CFML – Cold Fusion Markup language The table below compares the various server side scripting languages with PHP
| FEATURE | PHP | ASP | JSP | CFML |
|---|---|---|---|---|
| Learning curve | short | Longer than PHP | Longer than PHP | Longer than PHP |
| Web hosting | Supported by almost all hosting servers | Needs dedicated server | Fairly supported | Needs dedicated server |
| Open source | Yes | No | Yes | Both commercial and open source |
| Web services support | Built in | Uses the .NET framework | Uses add on libraries | Built in |
| Integration with HTML | Easy | Fairly complex | Fairly complex | Easy |
| MySQL support | Native | Needs third party drivers | Needs third party drivers | Current version has native support. Older versions use ODBC |
| Easily extended by other languages | Yes | No | Extended using Java classes and libraries. | Yes |
File extension and Tags In order for the server to identify our PHP files and scripts, we must save the file with the “.php” extension. Older PHP file extensions include
PHP was designed to work with HTML, and as such, it can be embedded into the HTML code.
The server interprets the PHP code and outputs the results as HTML code to the web browsers.
In order for the server to identify the PHP code from the HTML code, we must always enclose the PHP code in PHP tags.
A PHP tag starts with the less than symbol followed by the question mark and then the words “php”.
PHP is a case sensitive language, “VAR” is not the same as “var”.
The PHP tags themselves are not case-sensitive, but it is strongly recommended that we use lower case letter. The code below illustrates the above point.
<?php … ?>
We will be referring to the PHP lines of code as statements. PHP statements end with a semi colon (;). If you only have one statement, you can omit the semi colon. If you have more than one statement, then you must end each line with a semi colon. For the sake of consistency, it is recommended that you always end your statement(s) with a semi colon. PHP scripts are executed on the server. The output is returned in form of HTML.
The program shown below is a basic PHP application that outputs the words “Hello World!” When viewed in a web browser.
<?php echo "Hello world"; ?>
Output:
Hello world
PHP is a server-side scripting language used to develop static and dynamic websites or web...
What is a PHP Array? A PHP array is a variable that stores more than one piece of related data in a...
Potential security threats They are basically two groups of people that can attack your system...
In this tutorial, you will learn- PHP Data Types PHP Variable Use of variables Variable type...
Training Summary PHP is the most popular scripting language on the web. Without PHP Facebook,...
A Loop is an Iterative Control Structure that involves executing the same number of code a number...