PHP is a server-side scripting language, which means the PHP interpreter processes your code on the web server before any output reaches the browser. When a visitor requests a PHP page, the server reads the file, executes the PHP instructions, and sends the resulting HTML to the client. The browser never sees the PHP source code, only the generated output.
This execution model differs fundamentally from client-side languages like JavaScript, which run inside the browser. PHP has direct access to server resources: the file system, databases, environment variables, and server configuration. This makes it well-suited for tasks like reading from a database, writing log files, or processing form submissions.
A typical PHP file carries the .php extension and can contain a mix of HTML markup and PHP code blocks. PHP code is enclosed within the opening tag <?php and the closing tag ?>. Everything outside these tags is treated as raw HTML and passed through to the browser unchanged.
The PHP interpreter processes the file top to bottom. When it encounters a PHP block, it executes the instructions and replaces the block with any output those instructions produce. The echo and print statements send text to the output buffer, which is eventually flushed to the browser as part of the HTTP response.
Understanding the request-response cycle is essential. Each HTTP request to a PHP page triggers a fresh execution of the script. PHP does not maintain state between requests by default, which is why mechanisms like sessions and cookies exist to simulate continuity across page loads.
During development, enable error reporting by placing error_reporting(E_ALL); and ini_set('display_errors', 1); at the top of your script. This surfaces syntax and runtime errors immediately rather than showing a blank page.
<!DOCTYPE html>
<html>
<body>
<?php
// Server-side PHP block
$serverTime = date('Y-m-d H:i:s');
$language = 'PHP';
echo "<h1>Welcome to $language</h1>";
echo "<p>Server time: $serverTime</p>";
?>
<p>This paragraph is plain HTML - PHP never touches it.</p>
</body>
</html>The PHP block executes on the server, producing dynamic output for the heading and timestamp. The plain HTML paragraph passes through untouched. The browser receives only the final rendered HTML, with no trace of the original PHP tags.
- PHP runs on the server and sends generated HTML to the browser, never exposing source code.
- PHP blocks are delimited by
<?phpand?>tags within any.phpfile. - Each HTTP request triggers a fresh script execution; PHP is stateless by default.
- The
echostatement writes output into the HTTP response buffer. - Enable
E_ALLerror reporting during development to catch errors early.