PHP Basics
beginnerWhat You'll Learn
Theory
PHP (Hypertext Preprocessor) is a server-side scripting language designed specifically for web development. It powers millions of websites and content management systems like WordPress and Drupal.
Server-Side Scripting
Unlike JavaScript (which runs in the browser), PHP code executes on the server. The server processes PHP and sends only the generated HTML to the client:
Browser → HTTP Request → Server (PHP processes) → HTML Response → Browser renders page
This means users never see your PHP source code — only the output it produces.
PHP with HTML
PHP can be embedded directly into HTML using <?php ... ?> tags:
<!DOCTYPE html>
<html>
<body>
<h1><?php echo "Hello, World!"; ?></h1>
</body>
</html>Files with PHP code use the .php extension. The web server recognizes this extension and passes the file to the PHP interpreter before sending the result to the browser.
Why PHP for Web?
- Easy to learn — syntax similar to C and Perl
- Built-in web features — form handling, sessions, cookies, file uploads
- Database support — MySQL, PostgreSQL, SQLite, and more
- Large ecosystem — frameworks (Laravel, Symfony), CMS (WordPress, Drupal)
- Shared hosting — almost all web hosts support PHP
Why this matters
PHP powers a significant portion of the web, including WordPress, Facebook, and Wikipedia. Understanding server-side scripting and how PHP integrates with HTML is essential for building dynamic, data-driven websites.
What's next
In the next lessons, you'll dive deeper into each topic with hands-on examples and exercises.
Exercises
Personal Profile Page
Create a PHP page that stores your name, age, city, and profession in variables. Display them inside an HTML card with styled headings.
Expected Output:
An HTML page displaying Name, Age, City, and Profession in a styled card layout.