Chapter 1: Introduction to PHP
1.1 Web Servers and their Roles
- Web Server: A software that accepts requests from clients (browser) and sends back responses
(web pages).
Examples: Apache, Nginx, IIS.
Roles:
1. Hosts websites and serves content.
2. Handles HTTP requests/responses.
3. Works with PHP interpreter to execute PHP code.
1.2 Server-Side Scripting
- Code runs on server → Output (HTML) sent to client.
Unlike JavaScript (client-side), PHP is executed before reaching browser.
Advantages: secure, dynamic, database interaction.
1.3 Server-Side Technologies
- CGI (Common Gateway Interface): Early method of running scripts on server.
- Apache Modules, ISAPI: Extend server functions.
- ASP, ASP.NET: Microsoft’s server scripting.
- ColdFusion: Adobe’s scripting tool.
- JSP (JavaServer Pages): Java-based.
- PHP: Open-source, widely used.
- Python / Ruby on Rails: Modern alternatives.
Chapter 2: Introduction to PHP
2.1 Setting up the Environment
- Use XAMPP / WAMP / MAMP for PHP + Apache + MySQL.
- Install PHP interpreter (bundled with AMP packages).
2.2 PHP Editors
- IDEs/Text Editors: VS Code, Sublime, PhpStorm, Notepad++.
2.3 PHP Tags
Example:
echo "Hello World!";
?>
Chapter 3: PHP Syntax and Comments
3.1 Syntax
- Statements end with ;
- Case-sensitive variables ($x ≠ $X).
3.2 Comments
- Single-line: // comment or # comment
- Multi-line: /* comment */
Chapter 4: PHP Data Types
4.1 PHP Integers
- Whole numbers.
4.2 PHP Floating Point Numbers or Doubles
- Decimal numbers.
4.3 PHP Boolean
- true/false.
4.4 PHP Strings
- 'Hello' or "World".
4.5 PHP Arrays
- Collection of values.
4.6 PHP Objects
- Instances of classes.
4.7 PHP NULL
- No value.
4.8 PHP Resources
- Special handlers (e.g., database connection).
Chapter 5: Variables
5.1 Naming Variables
- Must start with $, case-sensitive, cannot start with number.
5.2 Variable Types
- Type Juggling → PHP auto-converts type.
- Type Casting → Manual conversion (int)$x.
5.3 Variable Scope
- Local: inside function.
- Global: outside function.
- Static: remains after function ends.
- Function Parameters: passed into functions.