List of Practical’s
Practical 1
Objective: Install and configure PHP, web server, and MySQL.
Install Apache, MySQL, and PHP (XAMPP).
Configure environment settings.
Run a sample PHP file.
Exercise:
1. Write a PHP program to print "Welcome to PHP".
2. Write a simple PHP program using expressions and operators.
Practical 2
Objective: Demonstrate decision-making control structures.
if statement
if-else statement
switch statement
Exercise:
1. Write a PHP program to find the largest of three numbers using if-else.
2. Write a PHP program to check the day of the week using a switch statement.
Practical 3
Objective: Demonstrate looping structures.
while loop
do-while loop
for loop
foreach loop
Exercise:
1. Write a PHP program to print numbers from 1 to 10 using while.
2. Write a PHP program to display elements of an array using foreach.
Practical 4
Objective: Array manipulation.
Indexed arrays
Associative arrays
Multidimensional arrays
Exercise:
1. Write a PHP program to store and display student names using an indexed array.
2. Write a PHP program to store and display student marks using an associative array.
3. Write a PHP program to store and display student details using a multidimensional
array.
Practical 5
Objective: String handling.
Calculate string length
Count number of words in a string
Use built-in string functions
Exercise:
1. Write a PHP program to find the length of a string.
2. Write a PHP program to count the number of words in a given string.
3. Write a PHP program demonstrating the use of built-in string functions.
Practical 6
Objective: Functions in PHP.
Simple functions
Parameterized functions
Exercise:
1. Write a simple PHP function to calculate the sum of two numbers.
2. Write a parameterized function to find the factorial of a given number.
Practical 7
Objective: Create a PDF document using graphics concepts.
Exercise:
1. Write a PHP program to generate a simple PDF document.
Practical 8
Objective: Object-Oriented Programming (OOP) in PHP.
Inheritance
Class constructors
Exercise:
1. Write a PHP program to implement inheritance.
2. Write a PHP program to create a constructor for initializing objects.
Practical 9
Objective: Introspection and serialization in PHP.
Exercise:
1. Write a PHP program demonstrating introspection and serialization.
Practical 10
Objective: Form controls.
Text box
Radio button
Check box
Buttons
Exercise:
1. Design a web page using various form controls.
Practical 11
Objective: Web page designing using selection controls.
List box
Combo box
Hidden field box
Exercise:
1. Design a web page using selection controls.
Practical 12
Objective: Data validation in PHP.
Exercise:
1. Write a PHP program to validate user inputs in a form.
Practical 13
Objective: Cookie and session management.
Exercise:
1. Write a PHP program to set and read cookies.
2. Write a PHP program to implement session management.
Practical 14
Objective: Sending and receiving email in PHP.
Exercise:
1. Write a PHP program to send and receive emails using PHP’s mail function.
Practical 15
Objective: Database interaction using MySQL.
Exercise:
1. Write a PHP program to enter data into a database.
2. Write a PHP program to retrieve and display data from a database.
Practical 16
Objective: Update and delete data in MySQL using PHP.
Exercise:
1. Write a PHP program to update data in a MySQL database.
2. Write a PHP program to delete data from a MySQL database.
This a Sample how to write a practical
Practical 2: Decision-Making Control Structures in PHP
Objective:
To write a PHP program demonstrating the use of decision-making control structures
including:
If statement
If-else statement
Switch statement
Theory:
Decision-making structures allow a program to execute different statements based on certain
conditions. In PHP, commonly used decision-making structures include:
1. If Statement – Executes a block of code if a specified condition is true.
2. If-else Statement – Executes one block of code if the condition is true, and another block if it
is false.
3. Switch Statement – Used when multiple conditions need to be checked; it selects one of
many blocks of code to execute.
Code Implementation:
1. If Statement Example
<?php
$age = 20;
if ($age >= 18)
{
echo "You are eligible to vote.";
}
?>
Explanation:
If $age is greater than or equal to 18, the message "You are eligible to vote." will be
displayed.
If $age is less than 18, nothing will be displayed since no alternative action is provided.
2. If-Else Statement Example
<?php
$marks = 45;
if ($marks >= 50)
{
echo "You have passed the exam.";
}
else
{
echo "You have failed the exam.";
}
?>
Explanation:
If $marks is 50 or more, the program prints "You have passed the exam."
Otherwise, it prints "You have failed the exam."
3. Switch Statement Example
<?php
$day = "Tuesday";
switch ($day)
{
case "Monday":
echo "Today is Monday.";
break;
case "Tuesday":
echo "Today is Tuesday.";
break;
case "Wednesday":
echo "Today is Wednesday.";
break;
default:
echo "Invalid day.";
}
?>
Explanation:
The program checks the value of $day.
If $day is "Tuesday", the message "Today is Tuesday." is displayed.
If $day matches another case, the respective message is displayed.
If $day does not match any case, the default message "Invalid day." is displayed.
Conclusion:
The if statement is useful for simple conditional checks.
The if-else statement allows execution of alternative blocks.
The switch statement is efficient for handling multiple conditions.
This practical helps understand control flow in PHP and allows writing dynamic programs.