Professional Documents
Culture Documents
PHP - Practical Material - 2024
PHP - Practical Material - 2024
Lab Manual
2246 NAL - 2
E-Commerce
[PRACTICAL ACTIVITY BOOK]
Prepared by
Dr. Vasanthi Muniasamy
1
Dr. Vasanthi Muniasamy, Department of Computer Science, Al-Mahala Female Campus
Index Page
1 4
2 3
3 3
4 5
5 4
6 3
7 4
8 4
2
Dr. Vasanthi Muniasamy, Department of Computer Science, Al-Mahala Female Campus
<?php
$a = readline("Enter the Number for a: ");
$b = readline("Enter the Number for b: ");
$c = readline("Enter the Number for c: ");
if($a > $b)
{
if($a > $c)
echo "Maximum num a = $a";
else
echo "Maximum num c = $c";
}
else
{
if($c > $b)
echo "Maximum num c = $c";
else
echo "Maximum num b = $b";
}
?>
1(b). Write a PHP Program to check the given number is odd or even. [2 Marks]
<?php
$a = readline("Enter the Number: ");
if ($a % 2==0)
{
echo "Given number is EVEN";
}
else
{
echo "Given number is ODD";
}
?>
3
Dr. Vasanthi Muniasamy, Department of Computer Science, Al-Mahala Female Campus
<?php
$fahrenheit = readline("Enter the fahrenheit: ");
$celsius = (($fahrenheit - 32) * 5) / 9;
$celsius = round($celsius, 3);
echo "Temperature in celsius is: $celsius";
?>
2(b). PHP Program to check whether a number is a disarium number or not. [2 Marks]
<?php
$num = readline("Enter the number");
$rem = 0;
$sum = 0;
$size = strlen($num);
$n = $num;
while ($n > 0) {
$rem = $n % 10;
$sum = $sum + pow($rem, $size);
$n = (int)($n / 10);
$size--;
}
if ($sum == $num)
echo "$num is a disarium number";
else
echo "$num is not a disarium number";
?>
4
Dr. Vasanthi Muniasamy, Department of Computer Science, Al-Mahala Female Campus
<?php
$number = 6;
$result = $number * $number;
echo "Square of 6 is: $result\n\n";
$number = -225;
$absoluteValue = abs($number);
echo "Absolute Value: $absoluteValue\n\n";
$numbers = [12, 7, 25, 8, 14];
$maximum = max($numbers);
echo "Maximum Value: $maximum\n\n";
$minimum = min($numbers);
echo "Minimum Value: $minimum\n\n";
$number = 99.5;
$roundedUp = ceil($number);
echo "Rounded Up: $roundedUp\n\n";
$number = 99.5;
$roundedDown = floor($number);
echo "Rounded Down: $roundedDown\n\n";
$base = 2;
$exponent = 3;
$result = pow($base, $exponent);
echo "2^3: $result";
?>
5
Dr. Vasanthi Muniasamy, Department of Computer Science, Al-Mahala Female Campus
<?php
$a = array(10, 30, 89, 64, 23);
$lar = $a[0];
$s = count($a);
for ($i = 0; $i < $s; $i++) {
if ($a[$i] > $lar)
$lar = $a[$i];
}
echo "Largest element in the array is $lar";
?>
<?php
$array = [
"Father_name" => "salem",
"Father_age" => 50,
"Father_occupation" => "Engineer",
"Mother_name" => "Fathma",
"Mother_age" => 45,
"Mother_occupation" => "Home maker",
];
foreach ($array as $key => $value) {
echo "$key : $value\n\n";
}
?>
6
Dr. Vasanthi Muniasamy, Department of Computer Science, Al-Mahala Female Campus
<?php
$day=date("l");
switch ($day) {
case "Sunday":
echo "It's the start of the week.";
break;
case "Wednesday":
echo "It's a weekday with various activities.";
break;
case "Friday":
echo "It's the weekend.";
break;
default:
echo "It's a regular day.";
break;
}
<?php
$age = 10;
$gender = "Female";
if ($age >= 18 and $gender == "Female")
echo "You are an adult Female.";
else
echo "You are not an adult Female.";
?>
7
Dr. Vasanthi Muniasamy, Department of Computer Science, Al-Mahala Female Campus
<?php
for ($i = 1; $i <= 3; $i++) {
for ($j = 1; $j <= 5; $j++){
echo "$i * $j = ". $i * $j. "\n";
}
echo "\n";
}
?>
<?php
$i = 1;
while ($i <= 10) {
echo "$i \n";
$i++;
}
?>
8
Dr. Vasanthi Muniasamy, Department of Computer Science, Al-Mahala Female Campus
<?php
$text = "welcome";
$length = strlen($text);
echo "Length of the string: $length\n\n";
$reverse = strrev($text);
echo "Reversed string: $reverse\n\n";
$upper = strtoupper($text);
echo "Upper string: $upper\n\n";
$text = "WELCOME";
$lower = strtolower($text);
echo "Lower string: $lower\n\n";
$wordcount = str_word_count($text);
echo $wordcount;
?>
9
Dr. Vasanthi Muniasamy, Department of Computer Science, Al-Mahala Female Campus
<?php
echo "Today is " . date("Y/m/d") . "\n";
echo "Today is " . date("Y.m.d") . "\n";
echo "Today is " . date("Y-m-d") . "\n";
echo date("M-d-Y h:m:s\n", mktime(10,11,35,11,27,2021));
echo "Today is " . date("l\n\n");
date_default_timezone_set("Asia/Calcutta");
echo "The time in" . date_default_timezone_get() . "is" . date("h:i:sa");
echo "\n";
date_default_timezone_set("America/New_York");
echo "The time in" . date_default_timezone_get() . "is" . date("h:i:sa");
echo "\n";
?>
10