What does PHP stand for?

What is PHP?

PHP is a programming language for developing dynamic Internet applications, the use of which has been increasing steadily since it was first introduced in 1995. PHP is used on millions of websites around the world. The language is constantly being developed, in December 2017 version 7.2 will be released.

The abbreviation PHP stands for PHP Hypertext Preprocessor. PHP enables developers to create dynamic Internet applications such as e-commerce systems, chats or forums. In contrast to static Internet pages, the content of a dynamic Internet application can change at any time due to inputs and actions by the user or new basic information that often comes from databases.

In particular, PHP supports the simple evaluation of forms with which a user can send data to a website. It enables cooperation with many different database systems. The vast majority of PHP developers use the MySQL database system or its spin-off MariaDB.

What are the advantages of PHP?

First, some reasons why PHP is so popular:

  • The language was created for the development of Internet applications.
  • It enables programs to be developed easily.
  • It supports different platforms.
  • It works very well with the widespread Apache web server, also within ready-made installation packages, for example XAMPP (see below).
  • It’s affordable and flexible.

Some properties of PHP should be considered in more detail:

  • Compared to other languages, PHP is easy to learn. This is mainly due to the fact that, unlike other languages, PHP was developed exclusively for web server programming and only contains the necessary components.
  • PHP is consistently supported by many types of web servers. Other languages ​​are only used on certain types of servers. A PHP programmer can use his knowledge later on a wide variety of systems.
  • PHP doesn’t cost anything. You don’t have to buy a compiler or a development system. Among other things, it can be used on the also freely available and widely used Apache web server under various operating systems.
  • An internet application can be executed either on a web server (server program) or in the web browser of the viewer of a website (client program). PHP programs are always server programs. Only the output of the programs is shown to the viewer. The viewer’s web browser only needs to be able to implement the HTML code sent by the server. It does not have to have any special properties related to the programming language of the web server. The pages can therefore also be displayed by older browsers.
  • In addition, unlike client programs, server programs have access to text files and databases on the server. This enables frequently required operations to be carried out, such as searching for specific data or transmitting data to the server.
  • The viewer can only draw a few conclusions about the generating program code or the source data. The programs cannot simply be copied by the viewer and used for their own purposes.
  • PHP runs on numerous operating systems, including Windows, macOS and Ubuntu Linux.

What do you need for creating PHP programs?

For your work with PHP and MySQL / MariaDB, you need a web browser to view or use the pages, as well as the following minimum equipment: a PHP-capable web server (for example Apache), PHP itself and the MySQL / MariaDB database server. For program development under Windows, you can use one of the freely available packages, such as the easy-to-install XAMPP. Version XAMPP 7.2 will be released in December 2017. New versions appear shortly after new versions of PHP, the version numbers are based on those of PHP.

The name XAMPP is used as an abbreviation for the most important components of the package: Apache, MariaDB, Perl and PHP. The X stands for the different operating systems. The Perl programming language was introduced in 1987. In particular, the components of Perl that are used for web development have influenced the later development of PHP. The XAMPP package also includes other useful software and is already preconfigured in suitable versions for Windows, Linux and macOS.

An example program

In this section follows an example of a typical use of PHP and MySQL / MariaDB. If you do not have any programming experience, this example should show you the result of the sequence described below:

  • Sending user input in a form (see Figure 1) to a web server,
  • composing an SQL command on a web server and sending this command to a database server,
  • the evaluation of the SQL command on a database server and thus the filtering and sorting of data from a database,
  • sending the result of the SQL command back to the web server,
  • embedding this result in the structure of an HTML document,
  • sending the HTML document back to the user and
  • the output of the dynamically created HTML document in his web browser (see Figure 2).

If you already have knowledge of another programming language, you will find many familiar elements in the code and the short comments, but also PHP-specific elements. Of course, this demo example is not yet suitable for a thorough learning of PHP.

It is a database that stores data from hard drives. Individual data from hard drives from a certain price group should be displayed, optionally sorted. The user selects the desired price group and, if necessary, ticks the sorting box (see Figure 1). After pressing the Send data button, the desired result is displayed after the above process (see Figure 2).

Structure of the database

A database in MySQL / MariaDB is accessed with a single table. You can see the structure of the table in Figure 3, the sample data in Figure 4.

The code of the program

The code of the file “preisgruppe.htm” follows:

<!DOCTYPE html>
<html>
<head>
<meta charset=”utf-8″>
<title>HTML, Formular</title>
<!– Einbettung von CSS-Styles –>
<style>
body {font-family:Verdana; font-size:11pt;
background-color:#f0f0f0}
</style>
</head>
<body>
<p>Anzeige der Festplatten aus der Preisgruppe:</p>
<!– Formular, Ziel ist die PHP-Datei auf dem Webserver –>
<form action=”preisgruppe.php” method=”post”>
<!– Radiobuttons zur Auswahl der Preisgruppe –>
<p><input type=”radio” name=”pr” value=”1″ checked=”checked”>
bis 120 € einschl.<br>
<input type=”radio” name=”pr” value=”2″>
ab 120 € ausschl. bis 140 € einschl.<br>
<input type=”radio” name=”pr” value=”3″>
ab 140 € ausschl.</p>
<!– Checkbox zur Auswahl der Sortierung –>
<p><input type=”checkbox” name=”prsort”>
Ausgabe nach Preis (absteigend) sortiert</p>
<!– Schaltflächen zum Absenden oder Zurücksetzen des Formulars –>
<p><input type=”submit”> <input type=”reset”></p>
</form>
</body>
</html>

The code of the file “preisgruppe.php” follows:
<!DOCTYPE html>
<html>
<head>
<meta charset=”utf-8″>
<title>PHP, Ergebnis</title>
<!– Einbettung von CSS-Styles –>
<style>
body {font-family:Verdana; font-size:11pt;
background-color:#f0f0f0}
table, td {border:1px solid black;}
</style>
</head>
<body>
<?php
// Verbindung zur Datenbank öffnen
$con = mysqli_connect(“”, “root”, “”, “hardware”);

// Beginn des SQL-Befehls
$sql = “SELECT hersteller, typ, preis FROM fp WHERE “;

// Weiterführung des SQL-Befehls, in Abhängigkeit der Auswahl
switch($_POST[“pr”])
{
case 1:
$sql .= “preis <= 120”;
break;
case 2:
$sql .= “preis > 120 AND preis <= 140”;
break;
case 3:
$sql .= “preis > 140”;
}

// Weiterführung des SQL-Befehls, in Abhängigkeit der Auswahl
if (isset($_POST[“prsort”]))
$sql .= ” ORDER BY preis DESC”;

// Absenden des SQL-Befehls und Speichern des Ergebnisses
$res = mysqli_query($con, $sql);
$num = mysqli_num_rows($res);
if($num > 0) echo “<p>Ergebnis:</p>”;
else         echo “<p>Keine Ergebnisse</p>”;

// Beginn einer HTML-Tabelle für das Ergebnis
echo “<table border=’1′>”;
echo “<tr><td><b>Hersteller</b></td><td><b>Typ</b></td>
<td><b>Preis</b></td></tr>”;

// Ermittlung und Ausgabe der einzelnen Datensätze des Ergebnisses
while ($dsatz = mysqli_fetch_assoc($res))
{
echo “<tr>”;
echo “<td>” . $dsatz[“hersteller”] . “</td>”;
echo “<td>” . $dsatz[“typ”] . “</td>”;
echo “<td>” . $dsatz[“preis”] . ” €</td>”;
echo “</tr>”;
}
echo “</table>”;

// Verbindung zur Datenbank schließen
mysqli_close($con);
?>
</body>
</html>

What is PHP