Getting Started

PHP Introduction

Discover PHP — the server-side scripting language that powers over 75% of the web.

What is PHP?

PHP (Hypertext Preprocessor) is a widely-used open-source server-side scripting language especially suited for web development. PHP code is executed on the server, and the result is returned to the browser as plain HTML.

Why Learn PHP?

  • Powers WordPress, Drupal, Laravel, and more
  • Runs on virtually every web hosting platform
  • Easy to embed in HTML
  • Large community and ecosystem
  • Connects easily to MySQL and other databases

How PHP Works

  1. Browser requests a PHP page
  2. Web server processes the PHP file
  3. PHP engine executes the code
  4. HTML is returned to the browser

The browser only sees the output — never the PHP code itself.

Example

php
<?php
// PHP tags delimit PHP code
echo "Hello, World!";

// Variables start with $
$name = "PHP";
$version = 8.2;
$isAwesome = true;

// String interpolation with double quotes
echo "PHP version: $version";
echo "Is awesome: " . ($isAwesome ? "yes" : "no");

// Comments
// Single line comment
# Also single line
/* Multi-line
   comment */

// Print with HTML
?>
<html>
<body>
    <h1><?php echo "Hello from PHP!"; ?></h1>
    <p>Version: <?= $version ?></p>
</body>
</html>
Try It Yourself