0% found this document useful (0 votes)
12 views33 pages

PHP Lab

The document outlines the PHP Programming Lab curriculum for II BCA students at Mannar Thirumalai Naicker College for the academic year 2024-2025. It includes a series of practical exercises covering various PHP programming concepts such as user input, palindrome checking, Armstrong numbers, mathematical calculations, visitor tracking, digital clock display, factorial calculation, array manipulation, and personal information display. Each exercise includes the aim, program code, and confirms successful execution of the programs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views33 pages

PHP Lab

The document outlines the PHP Programming Lab curriculum for II BCA students at Mannar Thirumalai Naicker College for the academic year 2024-2025. It includes a series of practical exercises covering various PHP programming concepts such as user input, palindrome checking, Armstrong numbers, mathematical calculations, visitor tracking, digital clock display, factorial calculation, array manipulation, and personal information display. Each exercise includes the aim, program code, and confirms successful execution of the programs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

MANNAR THIRUMALAI NAICKER COLLEGE (AUTONOMOUS)

PASUMALAI, MADURAI-625 004

DEPARTMENT OF COMPUTER APPLICATIONS

PHP PROGRAMMING LAB (23UCASP41)

Academic Year 2024-2025

II BCA- IV Semester
MANNAR THIRUMALAI NAICKER COLLEGE (AUTONOMOUS)
PASUMALAI, MADURAI-625 004

DEPARTMENT OF COMPUTER APPLICATIONS

NAME: Reg.No.

CLASS: II BCA SEMESTER:IV

SUBJECT:PHP PROGRAMMING LAB SUB.CODE:23UCASP41

This is to certify that this record is a Bonafide work done by the above mentioned
student. The certificate is awarded for the same.

HEAD OF THE DEPARTMENT STAFF IN-CHARGE


Mrs.M.Muthulakshmi, MCA,M.Phil.,MBA.,SET Mrs.R.Madhumitha.,MCA

Submitted for practical Examination held on ______________ at Mannar


Thirumalai Naicker College, Pasumalai and Madurai.

INTERNAL EXAMINER EXTERNAL EXAMINER


INDEX

S.NO DATE PROGRAM LIST PAGE SIGNATU

NO RE

Get name of the user from a form and show greeting text.
1

Write a PHP program to check whether given number is


2 palindrome or not.

3 Write a PHP program to check whether given number is


Armstrong or not.
Write a PHP program to find largest values of two numbers
4 using nesting of function.

5 Write a Mathematical calculator program.


Write a PHP program to keep track of the number of
visitors visiting the web page and to display this count
6 of visitors, with
proper headings.
Write a PHP program to display a digital clock which displays
7 the current time of the server.

8 Write a PHP program using function.

9 Write a PHP program to Array manipulation.

10 Write a PHP program to design personal information.

11 Write a PHP program to Read from existing file.

12 Write a PHP program to Write a file.


EX.NO:01
GREETING TEXT
DATE:

AIM:

To write a program for get the name of the user from a form and show greeting text.

PROGRAM:

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form method='POST'>
<h2>Please input your name:</h2>
<input type="text" name="name">
<input type="submit" value="Submit Name">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['name'])) {
$name =$_POST['name'];
echo"<h3> Hello $name</h3>";
}
?>
</body>
</html>

Result :

Thus the program has been executed successfully.

OUTPUT
EX.NO:02
PALINDROME CHECKING
DATE:

AIM:

To write a program for find the given number is palindrome or not.

PROGRAM:

<!DOCTYPE html>

<html>

<head>

</head>

<body>

<form method="POST">

<h2>Enter a number to check if it's a palindrome:</h2>

<input type="number" name="number" required>

<input type="submit" value="Check Palindrome">

</form><?php

function Palindrome($number){

$temp = $number;

$new = 0;

while (floor($temp)) {

$d = $temp % 10;

$new = $new * 10 + $d;

$temp = floor($temp / 10);

return $new;

}
if ($_SERVER['REQUEST_METHOD'] == 'POST'){

$input = $_POST['number'];

$num = Palindrome($input);

if($input == $num) {

echo "$input is a palindrome number";

} else {

echo "$input is not a palindrome";

}}

?>

</body>

</html></html>

Result :

Thus the program has been executed successfully.

OUTPUT
EX.NO:03
ARMSTRONG NUMBER CHECKING
DATE:

AIM:

To write a program for find the given number is Armstrong or not.

PROGRAM:

<html>
<body>
<h2>Enter the Number</h2><br>
<form action="" method="post">
<input type="text" name="number" />
<input type="submit" />
</form>
</body>
</html>
<?php
if ($_POST) {
$number = $_POST['number'];
$temp = $number;
$sum = 0;
while ($temp != 0) {
$rem = $temp % 10;
$sum = $sum + ($rem * $rem * $rem);
$temp = $temp / 10;
}
if ($number == $sum)
echo $sum." is Armstrong Number";
else
echo $sum." is Not an Armstrong Number";
}
?>

Result :

Thus the program has been executed successfully.


OUTPUT
EX.NO:04
NESTING OF MEMBER FUNCTION
DATE:

AIM:

To write a program for find the large value using nesting of member function.

PROGRAM:

<?php

if($_POST)

$a=$_POST['f'];

$b=$_POST['s'];

function big($a,$b)

if($a>$b

) return $a;

else

return $b; }

function

large($a,$b)

$n=big($a,$b);

echo'<br><br><table align="center" border="3"><tr align="center"><td>';

echo'<h1><font color="darkblue">Nesting Function</font></h1>';

echo'<b><u>Given Values:</u></b><br><br>First Value &nbsp;&nbsp;&nbsp; =$a";

echo"<br>Second Value =$b";

echo'<br><h3><font color="darkred" face="cooper black">Large value

='; echo" $n</font></h3></td></tr></table>";

large($a,$b); } ?>
Result :

Thus the program has been executed successfully.

OUTPUT
EX.NO:05
MATHEMATICAL CALCULATOR
DATE:

AIM:

To write a program for mathematical calculator.

PROGRAM:

<?php

if(isset($_POST['disp']))

$f=$_POST['f'];

$s=$_POST['s'];

$ch=$_POST['ch'];

switch($ch)

case 'ADDITION':

$res=$f+$s;

break;

case 'SUBTRACTION':

$res=$f-$s;

break;

case 'MULTIPLICATION':

$res=$f*$s;

break;

case 'DIVISION':

$res=$f/$s;

break;

?>

<html>
<body bgcolor="gold">

<form action="" method="post">

<table align="center" border="3" width="20%"><br><br>

<tr bgcolor="forestgreen"><td align="center" colspan="2">

<font color="white" face="arial black" size="5">CALCULATOR</font></td></tr>

<tr><td><input type="button" value="Enter First Input "></td>

<td><input type="text" name="f"></td></tr>

<tr><td><input type="button" value="Enter Second Input"></td>

<td><input type="text" name="s"></td></tr>

<tr><td><input type="button" value="Select Your Choice"></td>

<td><center><select name="ch">

<option>ADDITION</option>

<option>SUBTRACTION</option>

<option>MULTIPLICATION</option>

<option>DIVISION</option>

</center></select></td></tr>

<tr><td><input type="submit" value=" RESULT " name="disp"></td>

<td><input type="text" value="<?php echo @$res; ?>" readonly="true"/>

</td></tr></table>

</body></html>

Result :

Thus the program has been executed successfully.


OUTPUT
EX.NO:06 TRACK OF THE NUMBER OF VISITORS
DATE: VISITING THE WEB PAGE

AIM:

To write a PHP program to keep track of the number of visitors visiting the web page
and to display this count of visitors, with proper headings..

PROGRAM:
<?php
$file =
"visitor_count.txt"; if
(file_exists($file)) {
$count = file_get_contents($file);
$count++;
} else {
$count = 1;
}

file_put_contents($file, $count);
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Visitor Counter</title>
</head>
<body>
<h1>Welcome to Our Website!</h1>
<p>The number of visitors to this page is: <strong><?php echo $count;
?></strong></p>
</body>
</html>
Result :

Thus the program has been executed successfully.

Output:
EX.NO:07 DIGITAL CLOCK WHICH DISPLAY THE
DATE: CURRENT TIME

Aim:
To write a PHP program to display a digital clock which displays the current
time of the server

Program:
<?php
date_default_timezone_set("Asia/Kolkata");
$serverTime = date('H:i:s'); // Current time in HH:MM:SS format
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Digital Clock</title>
<style>
body {
font-family: 'Arial', sans-
serif; background-color:
#2c3e50; color: white;
text-align:
center; padding:
50px; margin: 0;
}

.clock {
font-size: 60px;
font-weight:
bold;
}
.container {
display: flex;

justify-content:
center; align-items:
center; height:
100vh;
}

</style>
</head>
<body>
<div class="container">
<div class="clock" id="clock"><?php echo $serverTime; ?></div>
</div>

<script>
function updateClock() {
const clockElement = document.getElementById('clock');
fetch('server_time.php')
.then(response => response.json())
.then(data => {
clockElement.innerHTML =
data.time;
});
}

setInterval(updateClock, 1000);
updateClock();
</script>
</body>
</html>

Result :

Thus the program has been executed successfully.


Output:
EX.NO:08
RECURSIVE FUNCTION
DATE:

AIM:

To write a program for display factorial value using Recursive Function

PROGRAM:

HTML FILENAME: Fact.html

<html>

<body bgcolor="darkkhaki">

<form action="factorial.php" method="post">

<center><br><br><br><br><br><br>

<table align="center" border="2" width="30%">

<tr align="center" bgcolor="darkblue"><td><font


color="white"><br><h1>FACTORIAL</h1></td></tr>

<tr bgcolor="chocolate"><td><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;

<font face="arial" size="6" color="white">Enter the Digit:</font>

<input type="text" name="n" size="15">

<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
nbsp;&n bsp;&nbsp;

<input type="submit" value="&nbsp;&nbsp;&nbsp; SEND &nbsp;&nbsp;&nbsp; "><br><br><br>

</td></tr></table>

</center>

</form>

</html>

PHP FILENAME: Factorial.php

<?php
$m=$_POST["n"];

function factorial($m)

if($m<2

) return

1; else

return($m*factorial($m-1));

$f=factorial($m);

echo'<br><table border="2" align="center"><tr><td>';

echo'<center><font face="arial" size="15"

color="crimson">FACTORIAL</font><br><br>'; echo"<b></b>";

echo'<font face="arial" size="10"><br>';

echo"Given Digit = $m <br>";

echo'<br><font color="green">';

echo "Factorial &nbsp;&nbsp;= $f";

echo"</center></font>";

echo'</td></tr></table>';

?>

Result :

Thus the program has been executed successfully.


OUTPUT
EX.NO:09
ARRAY MANIPULATION
DATE:

AIM:

To write a php program to manipulate arrays.

PROGRAM:

<html>

<body bgcolor="megenta">

<?php

$a=Array("crypt","php","dm");

$b=Array("mm","wap","php");

echo'<table align="center" bgcolor="white" border="2"><tr><td>';

echo'<h1 align="center"><u>Array Manipulation</u></h1>';

echo'<b><u>Given Array:</u><br> &nbsp; a=';

print_r($a);

echo'<br> &nbsp; b=';

print_r($b);

echo'</b><br><h3><font color="darkbrown">Array Ascending

a()&nbsp;&nbsp;:</font></h3>'; sort($a);

print_r($a);

echo'<br><h3><font color="fuchsia">Array Decending

a()&nbsp;&nbsp;:</font></h3>'; rsort($a);

print_r($a);

echo'<br><h3><font color="navy">Intersection of a(),b()&nbsp;:</font></h3>';

print_r(Array_intersect($a,$b));

echo'<br><h3><font color="darkred">Difference of a() & b():</font></h3>';

print_r(Array_diff($a,$b));

echo'<h3><font color="darkorange">Merging of a() & b()&nbsp;&nbsp;&nbsp;:</font></h3>';

print_r(Array_merge($a,$b));
echo'<br><h3><font color="darkgreen">Array Slicing in a()
&nbsp;&nbsp;&nbsp;&nbsp;:</font></h3>';

print_r(Array_slice($a,2));

echo'<br><h3><font color="dodgerblue">Array Splicing in a() &nbsp;&nbsp;:</font></h3>';

print_r(Array_splice($a,2));

echo'<br><h3><font color="chocolate">Array Poping from

a():</font></h3>'; echo'<b>Before :</b>';

print_r($a);

Array_pop($a);

echo'<br><b>After &nbsp; :</b>';

print_r($a);

echo'<br><h3><font color="lime">Array Pushing into

b():</font></h3>'; echo'<b>Before :</b>';

print_r($b);

Array_push($b,"50","30");

echo'<br><b>After &nbsp; :</b>';

print_r($b);

echo'<br><h3><font color="gold">Addition of b() Element:</font></h3>Sum=';

$i=Array_sum($b);

print_r($i);

echo"</td></tr></table>

";

?>

</body></html>

Result :

Thus the program has been executed successfully.


OUTPUT
EX.NO:10
PERSONAL DETAILS
DATE:

AIM:

To write a program for display our personal information using various tags.

PROGRAM:

<html>

<body text="red" bgcolor="orange"><table align="center" bgcolor="white"><tr><td>

<center><h1><hr><hr>** PERSONAL DETAILS **<hr><hr></h1></center>

<font color="blue"><pre><h3> NAME - <b><font face="Courier">Riya</font>

D.O.B - <b><font face="Courier">Sep 10,1995</font>

BLOOD GROUP - <b><font face="Courier">A+</font>

ADDRESS - <b><font face="Courier">Kenikarai</font>

CONTACT NO - <b><font face="Courier">04567-

220023</font>

EMAIL ID - <b><font face="Courier">[email protected]</font></font>

<font color="deeppink"><center><hr><hr><h1> ** MY FAVOURITES **</h1></center>

<hr><hr><font color="green"> FRIEND : <b><font face="Courier">

Akila</font> FOOD : <b><font face="Courier"> Idly</font>

COLOUR : <b><font face="Courier">Blue &

Pink</font> PLACE : <b><font

face="Courier">USA</font> SPORTS :

<b><font face="Courier"> Football</font>

DIRECTOR : <b><font face="Courier">Gowtham vasudev menan</font>

BOOK : <b><font face="Courier">The MONK Who Sold His

FERRARI</font> MOVIE : <b><font face="Courier">Ok Ok</font>

HOBBIES : <b><font face="Courier">Drawing </font>

</font></pre></h3></td></tr></table>

</body></html>
Result :

Thus the program has been executed successfully.

OUTPUT
EX.NO:11
READ FROM EXISTING FILE
DATE:

AIM:

To write a php program to read from existing file.

PROGRAM:

<html>

<body>

<form method="post">

<table align="center">

<font color="deeppink"><h1><u>READ THE FILE</u></h1></font>

<tr><td><b>Enter Your File Name&nbsp;:</b></td><td><input


type="text" name="file"></td></tr><br>

<tr><td><b>Choose File Extension :</b></td><br>

<td><select name="ext">

<option>.txt</option>

<option>.doc</option>

<option>.pdf</option>

</select></td></tr><br>

<tr><td><b>Content Of The File:</b></td><td><textarea rows="10" cols="16" name="data">

<?php echo @$contents;?></textarea></td></tr>

<tr colspan=2 align="center"><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<input type="submit" value="DISPLAY" name="disp">

</td></tr></table></form></body></html>

<?php

if(isset($_POST['disp']))

{
$f=$_POST['file'];

$ext=$_POST['ext'];
$data=$_POST['data'];

$file=$f.$ext;

if(file_exists($file))

$fo=fopen($file,"r");

$contents=fread($fo,filesize($file));

else

echo'<font color="deeppink" face="arial black"><center>File Not Exits</center></font>';

?>

Result :

Thus the program has been executed successfully.


Output:
EX.NO:12
WRITE A NEW FILE
DATE:

AIM:

To write a php program to write a new file.

PROGRAM:

<html>

<body>

<form method="post">

<table align="center">

<font color="deeppink"><h1><u>WRITE THE FILE</u></h1></font>

<tr><td><b>Enter Your File Name :</b></td><td><input type="text" name="file"></td></tr><br>

<tr><td><b>Choose File Extension :</b></td>

<td><select name="ext">

<option>.txt</option>

<option>.doc</option>

<option>.pdf</option>

</select></td></tr><br>

<tr><td><b>Write Content of File :</b></td><td><textarea rows="10" cols="16" name="data">

<?php echo @$contents;?></textarea></td><br>

<tr colspan="2" align="center"><td><input type="submit" value=" SAVE " name="disp">

</td></tr></table></form></body></html>

<?php

$f=$_POST['file'];

$ext=$_POST['ext'];

$data=$_POST['data'];

$file=$f.$ext;

if(file_exists($file))
{

echo'<font color="green" face="arial black"><center>Your File Already Exists</center></font>';

else
{

$fo=fopen($file,"w");

fwrite($fo,$data);

echo'<font color="deeppink" face="arial black"><center>Your Data is Saved</center></font>';

?>

Result :

Thus the program has been executed successfully.


OUTPUT:

You might also like