PHP Programming

PHP and the Request Cycle

PHP runs on the server: a browser requests a page, PHP executes, and only the resulting HTML travels back. Understanding this cycle explains everything about server-side code.

Key Concepts

  • PHP lives between tags, usually in .php files served by Apache/Nginx
  • echo outputs text into the response; the browser never sees your PHP source
  • Variables start with $: $name = 'Nepal'; types are dynamic
  • String interpolation works in double quotes: "Hello $name"; concatenation uses the dot: 'Hello ' . $name
  • Local testing: XAMPP/Laragon on Windows, or php -S localhost:8000 built-in server

Try It Yourself

Run php -S localhost:8000 (or XAMPP), create index.php that echoes 'Namaste' plus today's date with date(). View source in the browser — confirm no PHP is visible.