Skip to content

What Is PHP?

PHP is an open-source, server-side scripting language designed for producing web pages. Its first version was released in 1995 by Rasmus Lerdorf. The name stands for "PHP: Hypertext Preprocessor".

How does it work?

When a visitor requests a page, the web server runs the relevant PHP file. The PHP code fetches information from the database if needed, produces the result as HTML, and only that HTML is sent to the browser. The visitor cannot see the PHP code.

<?php
$name = "World";
echo "<p>Hello, " . htmlspecialchars($name) . "!</p>";
?>

Why is it so common?

  • Easy to learn: It can be written inside HTML and the result is seen immediately.
  • Runs everywhere: It comes ready in almost all hosting packages and runs on Linux, Windows and macOS.
  • Works with databases: It works directly with MySQL, MariaDB, PostgreSQL and SQLite.
  • Large ecosystem: Content management systems such as WordPress and frameworks such as Laravel and Symfony are written in PHP.
  • Still evolving: The PHP 8 series brought faster execution, stricter type checking and modern language features.

Example: reading data from a database

<?php
$pdo = new PDO("mysql:host=localhost;dbname=site;charset=utf8mb4", $user, $password);
$query = $pdo->prepare("SELECT title, body FROM pages WHERE slug = ?");
$query->execute([$slug]);
$page = $query->fetch();
?>

For secure PHP

  • Always use prepared statements in database queries.
  • Escape user data you print to the screen with htmlspecialchars().
  • Store passwords with password_hash().
  • Do not use PHP versions that are no longer supported; move to a current version.

Read on: What Is MySQL? · Web Software Development