DEPARTMENT OF COMPUTER ENGINEERING
Subject: Web Based Application Using PHP Subject Code:22619
Semester: 06 Course: CO6I-B
Laboratory No: L001B Name of Subject Teacher: Prof. Sneha
Patange
Name of Student: Shirish Pawar Roll ID:22203B0014
Experiment No 1,2,3
Title of Experiment 1. a. Install and configure PHP, web server, MYSQL
b. Write a program to print “Welcome to PHP”
c. Write a simple PHP program using expressions and
operators.
2. Write a PHP program to demonstrate the use of Decision-
making control structures using:
a. If statement
b. If-else statement
c. Switch statement
3. Write a PHP program to demonstrate the use of Looping
structures using:
a. While statement
b. Do-while statement
c. For statement
Application 1. Write PHP programs to implement basic PHP
functions(echo,print,var_dump())
2. STUDENT GRADE CALCULATOR- Create a script to manage
and analyse for a class. The script should achieve the
following obectives:
1. Input Grades: Assume grades are integers ranging from 0
to 100
2. Grade Classification:
Classification done on following categories-
A- 85% to 100%
B- 70% to 85%
C- 50% to 70%
D- 45% to 50%
Fail- below 45%
Generate a summary report once the input is complete, and
Page | 1
save it into a text file which should include:
1. Total number of students
2. Number of students in each grade category
3. The class average
4. The highest and lowest grades
3. Write PHP programs to implement for loop to print
Fibonacci series and prime number
1. Write a PHP program to implement echo and print statements.
ANS:
<?php
echo "This is echo satatment <br>";
$user = "GOGOGO";
echo "hello $user<br>";
echo "Welcome " . $user . "<br>";
print_r($user);
?>
2. Write a php script to implement var_dump function.
ANS:
<?php
$age = 25;
Page | 2
var_dump($age);
echo "<br>";
$name = "Lets goo";
var_dump($name);
echo "<br>";
$fruits = array("Apple", "Banana", "Cherry");
var_dump($fruits);
echo "<br>";
$hi = true;
var_dump($hi);
echo "<br>";
$novalue = null;
var_dump($novalue);
echo "<br>";
?>
3. Write a php program to implement operators.
ANS:
Page | 3
<?php
$math = 85;
$science = 78;
$english = 90;
$total_marks = $math + $science + $english;
$percentage = ($total_marks / 300) * 100;
if ($percentage >= 90) {
$grade = "A+";
} elseif ($percentage >= 80) {
$grade = "A";
} elseif ($percentage >= 70) {
$grade = "B";
} elseif ($percentage >= 60) {
$grade = "C";
} else {
$grade = "F";
echo "Total Marks: $total_marks<br>";
echo "Percentage: $percentage%<br>";
echo "Grade: $grade<br>";
echo $grade === "F" ? "Status: Fail" : "Status: Pass";
Page | 4
4. Write a php program to implement operators and control statements.
ANS:
<?php
$a = 25;
$b = 15;
$sum = $a + $b;
$product = $a * $b;
$isGreat = ($a > $b) ? "A is greater" : "B is greater or equal";
$number = 78;
$status = ($number % 2 === 0) ? "Even" : "Odd";
echo "Sum: $sum\n";
echo "Product: $product\n";
echo "$isGreat\n";
echo "Number $number is $status\n";
$marks = 65;
if ($marks >= 75) {
echo "Grade: Distinction\n";
} elseif ($marks >= 60) {
echo "Grade: First Class\n";
} elseif ($marks >= 50) {
echo "Grade: Second Class\n";
} elseif ($marks >= 35) {
Page | 5
echo "Grade: Pass\n";
} else {
echo "Grade: Fail\n";
?>
5. Write a php program to implement operators and control statements and store it into
file.
ANS:
<?php
$marks = 75;
$result = ($marks >= 40) ? "Pass" : "Fail";
$output = "Marks: $marks\nResult: $result\n";
file_put_contents("result.txt", $output);
echo "Result stored in 'result.txt'!";
?>
6. Write a php program store the summary of data into the file.
ANS:
<?php
Page | 6
$name = "John";
$marks = [70, 80, 90];
$total = array_sum($marks);
$percent = $total / count($marks);
$status = ($percent >= 40) ? "Pass" : "Fail";
$summary = "Name: $name\nTotal: $total\nStatus: $status\n";
$file = fopen("summary.txt", "w");
fwrite($file, $summary);
fclose($file);
echo "Summary saved to 'summary.txt'!";
?>
7. Write a PHP program to display Fibonacci series using for loop.
ANS:
<?php
$a=0;
$b=1;
$c=0;
$n=(int)readline("Enter a number:");
echo $a."\t".$b;
for($i=2; $i<$n; $i++)
Page | 7
$c=$a+$b;
echo "\t".$c;
$a=$b;
$b=$c;
?>
8. Write a PHP program to calculate prime using for loop.
ANS:
<?php
$num = (int)readline("Enter a number: ");
$isPrime = true;
if ($num < 2)
$isPrime = false;
else
for ($i = 2; $i * $i <= $num; $i++)
if ($num % $i == 0)
$isPrime = false;
break;
Page | 8
if ($isPrime)
{
echo "$num is a Prime Number.";
}
else
{
echo "$num is Not a Prime Number.";
}
?>
Dated signature of Teacher
Marks Obtained
Process Product Total (50)
Related (35) Related (15)
Page | 9