PHP Introduction
PHP stands for Hypertext Preprocessor. It is a widely-used, open-source scripting language designed specifically for web development. PHP code runs on a web server — not inside a browser — and it generates HTML output that the browser receives and displays.
PHP powers a significant portion of the internet. WordPress, Facebook (in its early years), Wikipedia's MediaWiki, and many e-commerce platforms are all built using PHP. Learning PHP opens the door to building dynamic, data-driven websites and web applications.
What Makes PHP Different from HTML
HTML is a static language. Once a web page is written in HTML, its content stays the same every time someone loads it. PHP is dynamic. A PHP script can change what it displays based on user input, data from a database, the current time, or any other condition.
Think of HTML as a printed flyer and PHP as a salesperson who reads the customer's name and prints a personalized letter every single time someone asks for one.
How PHP Works
When a visitor requests a PHP page, the following steps happen behind the scenes:
- The browser sends a request to the web server for a
.phpfile. - The server passes the file to the PHP interpreter.
- PHP runs the code inside the file — querying databases, processing logic, and generating output.
- The result (usually plain HTML) is sent back to the browser.
- The browser displays the output. The visitor never sees PHP code — only the result.
Where PHP Runs
PHP requires a server environment to execute. The three most common setups are:
- XAMPP — A free local server package for Windows, Mac, and Linux that includes Apache, MySQL, and PHP.
- WAMP / MAMP — Similar local server packages specific to Windows and Mac respectively.
- Online hosting — Most web hosting providers support PHP by default.
For practice, installing XAMPP on a local machine is the simplest starting point. Once installed, PHP files are placed in the htdocs folder and accessed through http://localhost/ in a browser.
PHP File Structure
A PHP file has the .php extension. It can contain plain HTML, PHP code, or a mix of both. PHP code is always written inside opening and closing PHP tags.
Basic PHP File Example
<!DOCTYPE html>
<html>
<body>
<?php
echo "Hello, World!";
?>
</body>
</html>
In the example above, <?php marks where PHP code begins and ?> marks where it ends. The echo statement outputs the text Hello, World! to the browser.
What PHP Can Do
- Generate dynamic page content based on user input or database data.
- Create, open, read, write, and delete files on the server.
- Collect and process form data submitted by users.
- Send and receive cookies to track user sessions.
- Add, modify, and retrieve data from databases like MySQL.
- Control user access and manage authentication.
- Encrypt sensitive data.
PHP Versions
PHP has evolved significantly over the years. PHP 5 introduced object-oriented programming features. PHP 7 brought major performance improvements. PHP 8 added named arguments, union types, match expressions, and the JIT compiler. The examples in this course are compatible with PHP 7.4 and above.
Key Points
- PHP is a server-side scripting language used to build dynamic web pages.
- PHP code runs on the server, not in the browser.
- PHP files use the
.phpextension. - PHP code is placed between
<?phpand?>tags. - A local server like XAMPP is needed to run PHP on a personal computer.
- PHP can interact with databases, handle files, process forms, and manage sessions.
