Introduction to PHP
Take The Quiz
What is PHP?
PHP is a server-side language that powers a huge share of the web (WordPress, Laravel…). It runs on the server, builds HTML, and sends it to the browser.
How PHP fits in
Unlike JavaScript in the browser, PHP runs before the page reaches the user. It can read databases, handle forms and generate dynamic HTML.
Your first PHP script
<?php
echo "Hello, world!";
?>Files end in .php
PHP code lives between <?php and ?>. Anything outside those tags is sent to the browser as-is.
Variables
PHP variables start with a $. No type declaration needed.
<?php
$name = "Ada";
$age = 30;
echo "Name: $name, Age: $age";PHP needs a server
Open a .php file directly and you just see the code. Run it with a local server (e.g. php -S localhost:8000) or Laragon/XAMPP.
Echo and string interpolation
<?php
$user = "Sam";
echo "Welcome, $user!"; // double quotes interpolate
echo 'Welcome, $user!'; // single quotes do NOT