1 of 2

Notes – PHP Introduction

PHP (Hypertext Preprocessor) is a server-side scripting language designed primarily for web development.

It is widely used to create dynamic and interactive websites.


Key Features of PHP

  • Server-side scripting: PHP runs on the server, generating dynamic content sent to the browser.
  • Easy to learn: Simple syntax, especially for those with basic knowledge of HTML and CSS.
  • Open-source: Free to use and well-supported by the community.
  • Database integration: Easily connects to databases, particularly MySQL.
  • Cross-platform: Works on various operating systems like Windows, Linux, and macOS.

PHP Syntax

  • PHP code is embedded within HTML using <?php ... ?> tags.
  • PHP statements end with a semicolon (;).
<?php
echo "Hello, World!";
?>

PHP Variables

  • Variables in PHP start with a dollar sign ($) followed by the variable name.
  • PHP variables do not need explicit type declarations.
<?php
$name = "John"; // String
$age = 25; // Integer
?>

How PHP Works

  1. Client Request: User requests a web page.
  2. PHP Server: PHP code on the server executes and generates HTML.
  3. Response: The server sends the generated HTML to the client’s browser.

PHP Common Uses


PurposeExample
Dynamic content generationDisplaying user data from a database
Form processingHandling contact forms or registrations
Session managementTracking users with sessions and cookies
Database operationsConnecting to MySQL to store/retrieve data