PHP ( Hypertext PreProcessor) is one of the most popular server-side web programming tools. The work of PHP in its simplest form comes down to processing the client's http request. Processing the request, in turn, consists of programmatically generating hypertext in accordance with the request parameters, after which the resulting markup is returned to the client. When a client (Internet browser) requests a regular static Internet page (most often with an html extension), the server returns the contents of this page as a response without changes “as is”. If a PHP page is requested, then during the processing of the request, the contents of the specified page are first processed by the PHP interpreter, and only then the result of this processing is sent to the client.

In other words, PHP is a hypertext preprocessor, which is reflected in its name. Pre processor because the hypertext undergoes final processing on the client side, the result of which we see in the browser window (the browser itself is the hypertext processor). We can say that PHP is a hypertext generator, since in most cases its work is programmatic generation from the contents of a database or from any other structured information hosted on the server. The abbreviation looks like PHP, and not like, for example, HPP or otherwise, since it originally stood for Personal Home Page Tools– tools for creating personal Internet pages. Thus, the first version of PHP decryption reflected its purpose, and the current one reflects the principle of operation.

PHP is a programming language that supports almost everything: variables, conditional statements, loops, functions, etc. PHP is object-oriented programming language– it supports , as well as conventional inheritance at the class level. PHP is a web programming language, since it was primarily created for the development of dynamic Internet sites and therefore contains a large number of ready-made solutions used in this area, such as:

  • processing and extraction of parameters http requests GET and POST;
  • formation and sending http headers;
  • storage infrastructure session data;
  • software services for working with cookies;

    cookies are text data saved by the browser on the client’s computer, which most often contains access parameters (login and password) or personal settings of the user. Cookies are generated by the browser and automatically sent to the server in the HTTP request headers during each remote access.


  • working with files FTP protocol;
  • working with databases using ;
  • support
  • support HTTP authorization;
  • messaging via email and much more.

In this section, I plan to briefly review the key points of using PHP to create simple web applications. The materials will be organized into several sections, each of which will contain examples with their source code. For independent experiments, you need any other site to which you have full access, and on the server of which PHP is installed.

PHP Programming Basics Adding PHP code to markup and the result of the hypertext preprocessor

PHP code is added directly anywhere in the HTML markup. The HTML markup itself may not exist at all, and the source code of the page can only be represented by a fragment of a PHP program. In any case, to insert PHP you need to use a special tag and place the program text inside it. This is done as follows:

During the operation of the PHP interpreter, sections are replaced with markup generated as a result of the operation of the program code placed in them. To display the result of the preprocessor, the operator is used echo, the arguments of which can be constants, variables, functions or various kinds of expressions, and the result is text. The simplest option might look like this:

If you open the source code of the resulting page in a browser, then there will no longer be any PHP there (unless, of course, a PHP interpreter is installed on the server). There's not much point in using the echo operator this way. The beauty of PHP is that the HTML generated can depend on request parameters, database contents, security policies, and much more. Analysis and processing of all this is done using familiar ones to almost everyone, such as loops, conditions, functions, etc. Looking ahead, I will give a small example of a PHP program using a loop and a conditional statement, so that the initial understanding of the hypertext preprocessor becomes more complete. The following program prints the factorial values ​​of numbers from 1 to 9.

Example program in PHP

The result of its operation will look something like this in the browser:

1!=1 2!=2 3!=6 4!=24 5!=120 6!=720 7!=5040 8!=40320 9!=362880

Organizing an application from multiple PHP files Short conditional or ternary operator

Below is a general view of a conditional assignment operator using the ternary operator:
$result = condition? expression if true: expression if false;

Example:
$result = ($a>5) ? $a+$b: $a-$b;

If a is greater than 5, then the result variable is assigned the value a+b, otherwise a-b.

An alternative to the if statement with more elseif constructs. Execution of statements begins with the case section whose value matches the value of the expression and continues through all subsequent cases until the break command is encountered - complete execution. The default section is an alternative to the else section in a conditional statement.

Switch ( expression) (case value 1: operator 1; case value 2: operator 2; case value 3: operator 3; default: operator executed by default; ) do loop body; while ( condition);

Same example:

$i=2; $f=1; do ( $f=$f*$i; $i++; echo $i,"!=",$f,"
"; ) while ($i