exp 5
exp 5
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.
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
ANS:
<?php
$user = "GOGOGO";
print_r($user);
?>
ANS:
<?php
$age = 25;
Page | 2
var_dump($age);
echo "<br>";
var_dump($name);
echo "<br>";
var_dump($fruits);
echo "<br>";
$hi = true;
var_dump($hi);
echo "<br>";
$novalue = null;
var_dump($novalue);
echo "<br>";
?>
ANS:
Page | 3
<?php
$math = 85;
$science = 78;
$english = 90;
$grade = "A+";
$grade = "A";
$grade = "B";
$grade = "C";
} else {
$grade = "F";
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;
$number = 78;
echo "$isGreat\n";
$marks = 65;
Page | 5
echo "Grade: Pass\n";
} else {
?>
5. Write a php program to implement operators and control statements and store it into
file.
ANS:
<?php
$marks = 75;
file_put_contents("result.txt", $output);
?>
6. Write a php program store the summary of data into the file.
ANS:
<?php
Page | 6
$name = "John";
$total = array_sum($marks);
fwrite($file, $summary);
fclose($file);
?>
ANS:
<?php
$a=0;
$b=1;
$c=0;
$n=(int)readline("Enter a number:");
echo $a."\t".$b;
Page | 7
$c=$a+$b;
echo "\t".$c;
$a=$b;
$b=$c;
?>
ANS:
<?php
$isPrime = true;
if ($num < 2)
$isPrime = false;
else
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.";
}
?>
Page | 9