Web Based Programming Lab — Free Notes & Tutorial
Free WBP Lab practicals for BCA — HTML, CSS, JavaScript, PHP lab programs and exercises at SikshaSarovar. Free Web Based Programming Lab course on SikshaSarovar.
This Web Based Programming Lab course is part of Siksha Sarovar and is 100% free for students in India — no sign-up required to read. It contains 35 structured lessons with examples, and pairs with our free online compiler and AI tutor.
What you will learn
- HTML
- CSS
- JavaScript
- PHP lab programs
Course content (35 lessons)
- Lab Setup: Server and SQL Dependencies — Required Dependencies (Server + SQL) To run all Web Based Programming Lab practicals (especially file upload and MySQL tasks), set up a local PHP server stack. Core Dependencies…
- Practical 1: Regular Expressions (Modifiers, Operators, Metacharacters) — Aim To write and test regular expressions in PHP that demonstrate pattern modifiers , operators (quantifiers) and metacharacters using the PCRE preg function family. Theory PHP's…
- Practical 2: Nested If Statement — Aim To demonstrate hierarchical decision making in PHP using a nested if statement that classifies a student result from two independent conditions — marks and attendance. Theory…
- Practical 3: Type Casting of Variables — Aim To perform explicit type casting of PHP variables between scalar and compound types — string, int, float, bool, array and object — and verify the exact conversion rules the…
- Practical 4: Menu Driven Program using Switch-Case — Aim To build a menu-driven calculator in PHP that dispatches the user's choice through a switch-case construct, including break , default and a division-by-zero guard. Theory A…
- Practical 5 (Part 1): for Loop — Aim To demonstrate PHP's for loop — the counter-controlled, entry-checked iteration construct — by printing the numbers 1 to 5. Theory The for loop packs the three pieces of…
- Practical 5 (Part 2): while Loop — Aim To demonstrate PHP's while loop — the entry-controlled loop used when the number of iterations is not known in advance — by printing the numbers 1 to 5. Theory while…
- Practical 5 (Part 3): do-while Loop — Aim To demonstrate PHP's do-while loop — the exit-controlled loop whose body is guaranteed to run at least once — by printing the numbers 1 to 5. Theory do { body } while…
- Practical 5 (Part 4): foreach Loop — Aim To traverse a PHP array with the foreach loop , the idiomatic construct for iterating arrays and other traversable structures without manual index bookkeeping. Theory foreach…
- Practical 6 (Part 1): Bubble Sort — Aim To implement Bubble Sort in PHP with the early-exit (swapped-flag) optimisation, printing the array after every pass to visualise how large values "bubble" to the end. Theory…
- Practical 6 (Part 2): Selection Sort — Aim To implement Selection Sort in PHP, printing the array after each selection so the growth of the sorted prefix is visible. Theory Selection Sort divides the array into a…
- Practical 6 (Part 3): Insertion Sort — Aim To implement Insertion Sort in PHP, tracing each insertion to show how the sorted prefix absorbs one new element per pass — the way a card player sorts a hand. Theory…
- Practical 6 (Part 4): Quick Sort — Aim To implement recursive Quick Sort in PHP with first-element pivoting, printing every partition step to expose the divide-and-conquer structure. Theory Quick Sort is a…
- Practical 7: array_pad, array_slice, array_splice, list (with foreach) — Aim To implement the PHP array functions array pad() , array slice() and array splice() together with list() destructuring, displaying every result with foreach wherever…
- Practical 8: User Defined Functions — Aim To show the application of user-defined functions in PHP — including typed parameters, return values and recursion — through three practical examples. Theory A user-defined…
- Practical 9: include, require, exit, die — Aim To write a program that passes control to another page using include and require , and terminates execution with exit() and die() . Theory Real sites are assembled from parts…
- Practical 10: Simple Login Form — Aim To create a simple login form in PHP with server-side validation that checks for empty fields and verifies a username/password pair. Theory This is the canonical…
- Practical 11: Usage of Cookie — Aim To show the usage of cookies in PHP — setting, reading, updating and deleting them — with a CLI simulation so the full lifecycle is observable in one run. Theory A cookie is a…
- Practical 12: Usage of Session — Aim To show the usage of sessions in PHP — starting a session, storing, reading and updating data in $ SESSION , and destroying it on logout. Theory HTTP is stateless : each…
- Practical 13: OOP Concepts in PHP — Aim To implement the core OOP concepts of PHP — class, object, constructor, visibility, inheritance, method overriding and encapsulation — using a Person base class and a Student…
- Practical 14: Form Handling using $_GET, $_POST, $_REQUEST — Aim To handle a personal-information form in PHP and retrieve the submitted data using the $ GET , $ POST and $ REQUEST superglobals. Theory When a form is submitted, PHP parcels…
- Practical 15: Login Form Design and Validation in PHP — Aim To design a login form and validate it with PHP — server-side field checks plus hashed password verification using password hash() / password verify() . Theory Validation must…
- Practical 16: Admin Login and Logout using Session Variables — Aim To create an admin login and logout system in PHP where the logged-in state and the admin's details are held in session variables . Theory Because HTTP is stateless, "being…
- Practical 17: Create a File — Aim To write a PHP program that creates a new file on disk and writes initial content into it. Theory PHP's classic file API is a three-step handle sequence: fopen($path, $mode)…
- Practical 18: PHP Library Functions for Files and Directories — Aim To use PHP's built-in library functions for files and directories — creating, copying, renaming, inspecting, listing and deleting — in one self-cleaning demonstration. Theory…
- Practical 19: Read and Display File Content — Aim To read a previously created file and display its content using PHP's file-reading functions. Theory PHP offers several reading strategies with different memory profiles: -…
- Practical 20: Modify Existing File Content — Aim To modify the content of an existing file — replacing a word and appending a new line — and display the file before and after the change. Theory The workhorse pattern is…
- Practical 21: Web Page for File Upload and Download — Aim To create a web page that provides file uploading and file downloading using PHP. Theory File upload needs two cooperating pieces. The form must declare method="post" and…
- Practical 22: Upload and Display Image in PHP — Aim To design a form that uploads an image and displays it on the page using PHP. Theory The upload pipeline is the same as Practical 21 — a method="post" form with…
- Practical 23: phpMyAdmin Operations (Import, Structure, SQL, Users/Privileges) — Aim To use phpMyAdmin to import data, review data and structure, run SQL statements, and create users with privileges — and to reproduce the same workflow programmatically with…
- Practical 24: Create a MySQL Database — Aim To write a PHP program that creates a MySQL database . Theory Creating a database is the one operation performed while connected to the server only — the DSN carries no dbname…
- Practical 25: Create Table and Insert Records using Form — Aim To create a table and insert a few records into it using form data , via PDO prepared statements. Theory CREATE TABLE defines each column as name + type + constraints : here…
- Practical 26: Select All Records and Display in Table — Aim To select all records from a table and display them in tabular form. Theory Reading rows with PDO is a two-step: run the query, then fetch . $pdo- query("SELECT ...") returns…
- Practical 27: Modify Table (Delete / Modify / Add) — Aim To modify a table by performing delete, modify and add operations. Theory "Modifying a table" happens at two different levels. DDL (Data Definition Language) changes the…
- Practical 28: Check Whether Page is Called from HTTP or HTTPS — Aim To write a PHP script that checks whether the page is called from https or http . Theory HTTP and HTTPS differ by one layer: HTTPS is ordinary HTTP tunnelled through TLS ,…
Practical 1: Regular Expressions (Modifiers, Operators, Metacharacters)
Aim
To write and test regular expressions in PHP that demonstrate pattern modifiers, operators (quantifiers) and metacharacters using the PCRE preg_* function family.
Theory
PHP's regex engine is PCRE (Perl Compatible Regular Expressions), exposed through preg_match(), preg_match_all(), preg_replace() and preg_split(). A pattern is written between delimiters (commonly /pattern/) and may be followed by modifiers that change engine behaviour:
i— case-insensitive matchingm— multiline:^and$anchor at every line boundarys— dotall:.also matches newlinex— extended: whitespace inside the pattern is ignored (self-documenting patterns)u— treat pattern and subject as UTF-8
Metacharacters carry special meaning: ^ (start anchor), $ (end anchor), . (any character), \d (digit), \w (word character), \s (whitespace), \b (zero-width word boundary), plus character classes like [a-z] and the negated form [^a-z]. Operators/quantifiers control repetition: * (0 or more), + (1 or more), ? (0 or 1), {n} / {n,m} (bounded), and | (alternation). Quantifiers are greedy by default; appending ? makes them lazy. Note the return contract: preg_match() returns 1 on match, 0 on no match and false on a malformed pattern — so === 1 is the robust production idiom.
Requirements
- XAMPP/WAMP with PHP 8.x (or standalone PHP CLI)
- Code editor (VS Code)
- Browser (Chrome/Edge) or terminal
Procedure
- Start Apache from the XAMPP Control Panel.
- Create the folder
C:\xampp\htdocs\wbplaband save the program asp01_regex.phpinside it. - Type the code from the snippet below and save.
- Run it at
http://localhost/wbplab/p01_regex.php, or from the terminal withphp p01_regex.php. - Edit the
$samplesarray, predict each MATCH/NO MATCH, then re-run to confirm.
Explanation of the Code
$patternsis an associative array mapping a human-readable label to a PCRE pattern. The first pattern/^web[a-z]\d{2}$/ianchors the whole string (^...$), requires the literalweb, any run of letters ([a-z]), then exactly two digits (\d{2}); theimodifier is whyWebDev23matches despite its capital letters.- The second pattern
/\d+/uses the+operator — at least one digit anywhere in the subject. - The third pattern
/\bphp\b/iuses the\bword-boundary metacharacter sophpmatches only as a whole word, never inside a longer token likephpMyAdmin. - The nested
foreachfeeds every string in$samplesto `preg_match(
Continue reading: Practical 1: Regular Expressions (Modifiers, Operators, Metacharacters) →
Frequently asked questions
Is the Web Based Programming Lab course really free?
Yes. The entire Web Based Programming Lab course on Siksha Sarovar is free to read with no account required. You can optionally sign in with Google to save your progress.
Do I get a certificate for Web Based Programming Lab?
Yes — finish the lessons and pass the quiz to earn a free, verifiable certificate you can share on LinkedIn or with recruiters.
Can I run code while learning?
Yes. The built-in online compiler runs C, C++, Python, Java, PHP, JavaScript, C# and SQL directly in your browser — no installation needed.