What is PHP

What is PHP

What is PHP

Let's start by defining what PHP is exactly. It is difficult to give a complete picture of this language in one sentence, so we will describe it with the following three characteristics:

PHP is a hypertext (HTML) preprocessor.
PHP is a server-side programming language.
PHP is a scripting, interpreted programming language.

Why PHP is needed

Let's explain each of the definitions and find out in what tasks PHP will be useful.

The main task of PHP is to "animate" HTML pages.

Regular HTML pages are static. Static (or immutable) means that after the page is created and uploaded to the site, each time the page is accessed, the browser will show it to any user unchanged.

But this is not always enough.

Almost always, users come to the site for information that is changing all the time, and you need to display its current state. For instance:

  • show the exchange rate;
  • tell the weather for tomorrow;
  • display a counter of page visits.

If you use only HTML, then you will not be able to solve such problems. This is where we need PHP. It accepts an incoming request from the web server, executes the script, and returns the result to the web server in the form of finished HTML code. The server sends this result to the browser to the user, who in turn displays it to the user. After that, you can see the fresh exchange rate, weather, and anything else.

PHP allows you to modify a web page on the server just before it is sent to the browser. Let's see how it works. PHP can execute code - the so-called scripts. During execution, PHP can change or dynamically create any HTML-code, which is the result of script execution. The server then sends this code to the browser. At the same time, the browser does not know how this page was formed - it was statically typeset by the layout designer, or dynamically created with the participation of PHP. It doesn't matter, because the browser always works only with what it received from the server.

Let's remember that a script  is a server-side program that runs in response to a request from the browser.

Now we can understand why PHP is called a hypertext preprocessor. When the browser requests a page with an address that ends with .php, the web server contacts PHP and asks it to execute the script from the file at that address.

Executing a script is also called its interpretation , and PHP itself is called an interpreter .

Where PHP is used

The main area of ​​application of the PHP language is the web, that is, the sites that we visit every day through the browser of a computer or smartphone. It is important to understand that the web is not the entire Internet, but only the largest and most popular part of it. In addition to the web, e-mail, instant messengers, file-sharing services, network games and much more work via the Internet.

Almost every site on the Internet runs on PHP. This language is great for any dynamic website, including:

  • social networks;
  • blogs and forums;
  • online stores;
  • browser games.

Installation and use

In our course we will be working with PHP 8

Where to download PHP?

We recommend using the OpenServer software build . After downloading and installing on your computer there will be a fresh version of PHP, a web server, a database, and many other programs and tools for easy work. We will tell you more about installation and use in the first lecture.

What a PHP script looks like

A typical PHP script is a collection of expressions. Each expression starts on a new line and ends with a semicolon.

An expression is an instruction that tells the PHP interpreter to do one thing, such as adding two numbers or printing information to the screen. Let's take a look at the simplest scenario. It will print one line to the screen: "Hello World!":


Note that in this example we have used an additional snippet - ?>. We use it to tell the server where our PHP script ends. If our code is the last in the document, and nothing follows after it, this fragment is optional.