Lesson 1 of 50 – Introduction to PHP
2%

Introduction to PHP

Welcome to the PHP tutorial! In this lesson, you will learn what PHP is, why it is used, its features, and how to write your first PHP program.

1. What is PHP?

PHP stands for PHP: Hypertext Preprocessor. It is a popular server-side scripting language used to develop dynamic websites and web applications.

PHP code runs on a web server. The server processes the PHP code and sends the resulting output, usually HTML, to the user's browser.

Example:
<?php
echo "Hello, World!";
?>
Output:
Hello, World!

The echo statement displays output. The PHP opening tag is <?php, and the closing tag is ?>.

2. What is Server-Side Scripting?

Server-side scripting means that code is executed on a web server instead of directly in the user's browser.

For example, when a user opens a PHP page:

  1. The browser requests a PHP page.
  2. The web server receives the request.
  3. The PHP interpreter executes the PHP code.
  4. The server sends the generated output to the browser.
  5. The browser displays the resulting page.

PHP is commonly used for form processing, database operations, login systems, and content management.

3. Features of PHP

  • PHP is open-source.
  • It is designed for web development.
  • It can generate dynamic web pages.
  • It supports databases such as MySQL.
  • It supports procedural and object-oriented programming.
  • It can process HTML forms.
  • It supports sessions and cookies.
  • It can run on commonly used operating systems.
  • It can be used to build APIs and web applications.

4. Uses of PHP

PHP can be used to create:

  • Dynamic websites
  • Student management systems
  • Online admission forms
  • Login and registration systems
  • Library management systems
  • Content management systems
  • E-commerce websites
  • Database-driven applications
  • REST APIs

For example, you can use PHP and MySQL to build a student registration system that stores student details in a database.

5. PHP and HTML

PHP can be written inside an HTML file saved with the .php extension.

Example:
<!DOCTYPE html>
<html>
<head>
    <title>My First PHP Page</title>
</head>
<body>

    <h1>Welcome to PHP</h1>

    <?php
        echo "I am learning PHP.";
    ?>

</body>
</html>
Output displayed in the browser:

Welcome to PHP

I am learning PHP.

Save this example as first.php and run it through a PHP-enabled web server. Opening the file directly in a browser will not execute the PHP code.

6. PHP File Extension

PHP files commonly use the .php extension.

File Name Purpose
index.php Main website page
login.php Login processing
register.php User registration
database.php Database connection code

7. Advantages of PHP

  • It is free to use.
  • It has a large community and ecosystem.
  • It integrates with HTML.
  • It supports many database systems.
  • It can be used for small and large web projects.
  • It is widely supported by web hosting providers.

Practical Assignment

Complete the following tasks:

  1. Create a file named first.php.
  2. Display your name using the echo statement.
  3. Display your institute name.
  4. Create an HTML heading using PHP and HTML together.
  5. Run the file using a PHP-enabled web server.
Starter Code:
<?php
echo "My Name is Rahul";
echo "<br>";
echo "Welcome to Soopro Pathshala";
?>

Replace Rahul with your own name.

Quick Quiz

1. What does PHP stand for?




2. Where is PHP code normally executed?




3. Which extension is commonly used for PHP files?