Lesson 4.1. Introduction to PHP


PHP originally meant Personal Home Page. it became later a recursive acronym: PHP Hypertext P rocessor. PHP is an open source language designed for web applications. PHP is used to generate dynamically HTML pages from the server.

Historically, HTML pages were stored in .html files. All users fetched the same page from the server. Quickly, the need for personalized pages were felt. For example, to authenticate a user and display only information that concerns him, such as his messages. this is why PHP has been designed for. It allows to create a dynamique (or personalized, or specifics) HTML pages.

PHP, a server side language

If your new to PHP, you have to understand the fundamental difference between PHP and HTML: HTML is interpreted on the client side, while PHP is executed on the server side. To simplify the difference between client and server:

The media on which you are currently viewing this page is the client. HTML languages, CSS, JavaScript are client-side languages. It is usually the browser that runs these scripts.

The languages PHP, ASP.NET, node.js are server-side languages, they run on the server. It is the result of execution (usually HTML) which is sent to the client.

The following diagram summarizes the principle of the relationship between the client and the server in the case of a dynamic website.

General diagram of the execution of a PHP script (client / server)

  1. The user requests a page by entering its URL, for example https: // lucidar.me which will actually be https: // lucidar.me / index.php.
  2. The server runs the script index.php which is at the root of the site. The result of this processing is HTML code.
  3. The HTML code is sent via the internet to the client.
  4. The HTML code is interpreted, then rendering is displayed in the browser.


Here is an example of a PHP script below. You will find that the two languages (HTML and PHP) are mixed in the same file. Here, HTML is sent to client as is, while PHP is running on the server. This is the output of the PHP <h1> Hello World </h1> which is inserted in the HTML:

    <title>PHP Test</title>
  <body><a class="btn btn-primary" href="/fr/web-dev-class/lesson-4-01-introduction-to-php/" role="button"><span class="d-md-inline d-none">Cours 3.1 </span><i class="fi-cnsrxl-chevron-solid"></i></a>
    <?php echo '<h1>Hello World</h1>'; ?> 

We understand here that the echo function will allow to display content in the HTML page. This instruction is similar to the C / C++ printf () function.


Write a PHP script that displays the 6 heading titles.

Headings created in HTML and PHP

See also

Last update : 10/10/2022