Aral Code

PHP Tutorial

PHP is a server-side language that builds web pages before they're sent to the browser. It powers a huge part of the web, including WordPress (used by about 4 in 10 websites), Facebook's early versions, and countless school portals, online shops and enrollment systems.

This free course has 17 lessons. Each one shows PHP code and the output it produces, with a Taglish summary and a quick quiz. By the end, you'll build a working web app that saves data in a database.

What you need

  • Basic HTML, because PHP mostly produces HTML.
  • A local server such as XAMPP (free), which includes PHP and MySQL. Lesson 2 shows how to set it up.
  • Knowing a little SQL helps for the database lessons.

What you'll be able to do

  • Write PHP inside HTML pages and run them on a local server
  • Use variables, arrays, loops and functions
  • Handle forms safely with GET and POST
  • Validate input and protect your site from common attacks
  • Remember users with sessions and cookies
  • Save and read data in MySQL using PDO

All lessons

Getting Started

  1. Introduction to PHPWhat PHP is, how server-side code differs from HTML and JavaScript, what PHP is used for, and what a first PHP page looks like.
  2. Getting Started with PHP — XAMPP and Your First PageInstall XAMPP, start Apache and MySQL, put PHP files in htdocs, open them through localhost, and use the built-in PHP server.
  3. PHP Syntax — echo, Comments and Mixing PHP with HTMLThe basic rules of PHP — tags, statements and semicolons, echo and print, comments, case sensitivity, and the clean ways to mix PHP with HTML.

Basics

  1. PHP Variables and Data TypesCreate PHP variables with $, learn the data types (string, int, float, bool, array, null), check them with var_dump and gettype, and convert between types.
  2. PHP Strings and String FunctionsSingle vs double quotes, joining with the dot operator, and essential string functions — strlen, strtoupper, ucwords, trim, str_replace, strpos, substr, explode, implode, number_format and sprintf.
  3. PHP Operators and Math FunctionsArithmetic, assignment, comparison (== vs ===), logical, string and null-coalescing operators in PHP, plus round, floor, ceil, max, min, rand and intdiv.

Control Flow

  1. PHP if, else, switch and matchMake decisions in PHP with if, elseif and else, switch, and the modern match expression, with grade descriptors and a store menu.
  2. PHP Loops — for, while, do-while and foreachRepeat code in PHP with for, while, do-while and foreach loops, build HTML tables and lists from loops, and use break and continue.

Arrays & Functions

  1. PHP Arrays — Indexed, Associative and MultidimensionalStore lists and records in PHP arrays — indexed arrays, associative arrays with keys, arrays of arrays, adding, removing and checking items, and printing them with print_r.
  2. PHP Array Functions — Sorting, Filtering and MappingSort arrays with sort, rsort, asort, ksort and usort; summarize with array_sum and count; transform with array_map, array_filter, array_column and array_slice.
  3. PHP FunctionsWrite PHP functions with parameters, default values, type declarations and return types, pass by reference, use variable scope correctly, and write arrow functions.

Web Development

  1. PHP Forms — GET, POST and htmlspecialcharsReceive form data in PHP with $_GET and $_POST, know when to use each method, display user input safely with htmlspecialchars, and handle a form on the same page.
  2. PHP Form ValidationValidate form input on the server — required fields, lengths, numbers, emails and PH mobile numbers with filter_var and preg_match — show error messages and keep what the user typed.
  3. PHP include, require and Working with FilesReuse headers, footers and functions with include and require, read and write text files with file_get_contents and file_put_contents, work with JSON files, and handle file uploads safely.
  4. PHP Sessions and Cookies — Logins and Remembering UsersRemember data between pages with sessions, build a login and logout, protect pages, hash passwords with password_hash, and use cookies for simple preferences.

Databases

  1. PHP and MySQL with PDO — Connect, Query and Prepared StatementsConnect PHP to a MySQL database with PDO, read rows with SELECT, insert, update and delete safely with prepared statements, and prevent SQL injection.
  2. PHP Final Project — Student Feedback Board with MySQLBuild a complete PHP and MySQL web app — a feedback board where students post messages — with validation, prepared statements, escaping, CSRF protection and a simple admin delete.