Skip to content
application · programming · backend

The web's workhorse,PHP.

Hypertext Preprocessor — the dynamic, server-side scripting language that embeds directly into HTML and powers the classic LAMP stack. From WordPress to Laravel and Symfony, PHP still drives a huge share of the web. This guide covers install, syntax basics, and reusable functions.

The P in LAMP

PHP runs on the server, generates HTML for the browser, and pairs with Linux, Apache, and MySQL in the stack that has powered countless servers across the globe for decades.

  • Embedded — code lives inside HTML between PHP tags.
  • Modern — PHP 8.x adds JIT, enums, and strict typing.
  • Reusable — practical string helpers like ss_between.
Hypertext PreprocessorAcronym
PHP 8.xModern line
LAMPStack
php -SDev server

Start here

Overview

PHP (Hypertext Preprocessor) is a dynamic, server-side scripting language famed for embedding directly into HTML and powering the classic LAMP stack. It runs on the server, generates HTML for the browser, and drives a huge share of the web — including WordPress, Laravel, and Symfony applications.

This guide covers the background, install, syntax basics, and reusable functions.

Background

Information

PHP is a programming language known as Hypertext Preprocessor, originally standing for Personal Home Page. It is widely used for web development, famed for its ease of use and ability to be embedded directly into HTML. PHP is dynamic and server-side, allowing developers to build robust web applications that can handle complex data-driven tasks.

PHP supports a wide range of databases, has rich built-in functions, and can interact with various web services. It’s also part of the classic LAMP (Linux, Apache, MySQL, PHP) stack which powers countless servers across the globe. PHP continues to evolve with regular updates that improve its performance, security features, and modern language capabilities.

Get the CLI

Install

PHP is packaged for every major OS. Install the CLI and verify the version:

Terminal window
# Debian / Ubuntu
sudo apt install php-cli -y
# macOS (Homebrew)
brew install php
# Check the version
php -v

Run a script or start the built-in dev server (never for production):

Terminal window
php script.php
php -S localhost:8000

Language basics

Syntax

PHP code lives between <?php ... ?> tags; everything outside is sent to the browser as plain HTML:

<?php
$name = "KBVE";
$count = 3;
function greet(string $who): string {
return "Hello, {$who}!";
}
echo greet($name);
for ($i = 0; $i < $count; $i++) {
echo "Row {$i}\n";
}

Reusable helpers

Functions

  • This is an example of the ss_between function written in php.

    // Credit: AADude
    function ss_between($string,$start,$end) {
    $string=" ".$string; //The string.
    $startpos=strpos($string,$start); //Find the position of the start string.
    //Check if $startpos equals zero.
    if ($startpos == 0) {
    //If $startpos does equal zero, do this:
    return false; //Return false.
    }
    else {
    //If $startpos doesn't equal zero, do this:
    $startpos+=strlen($start); //Add the string length of $start to $startpos.
    $endpos=strpos($string,$end,$startpos)-$startpos; //Find the string position of $end.
    return substr($string,$startpos,$endpos); //Return the new value.
    }
    }
    // Proof of Of Concept
    $source = "U:holybyteE:[email protected]";
    $u = ss_between($source, "U:", "E:");
    // $source = line 1 of text file
    echo $u;
    // return username

Questions

Frequently asked

What is PHP used for?

PHP is a server-side scripting language used mainly for web development. It runs on the server, generates HTML sent to the browser, and powers dynamic, data-driven applications and content management systems like WordPress, Drupal, and Laravel apps. It is the P in the classic LAMP stack.

What does PHP stand for?

PHP is a recursive acronym for PHP Hypertext Preprocessor. It originally stood for Personal Home Page, reflecting its origins, but was renamed as it grew into a general-purpose web scripting language.

Is PHP still relevant in modern web development?

Yes. PHP powers a large share of the web, including WordPress. Modern PHP 8.x brings the JIT compiler, strong typing, attributes, enums, and major performance gains, and frameworks like Laravel and Symfony keep it a productive, well-supported choice for backends.

How do I embed PHP in HTML?

Wrap PHP code in <?php ... ?> tags anywhere inside an .php file. The server executes the code between the tags and replaces it with its output, while everything outside the tags is sent to the browser as plain HTML.

What is the LAMP stack?

LAMP is a classic web hosting stack of Linux (OS), Apache (web server), MySQL (database), and PHP (scripting language). It is a fully open-source foundation that has powered countless websites and web applications for decades.