MADURAI KAMARAJAR UNIVERSITY
DEVANGA ARTS COLLEGE
Reaccredited and Graded ‘A’ by NAAC
ARUPPUKOTTAI - 626101
RECORD NOTE BOOK
DEPARTMENT OF COMPUTER SCIENCE (UG)
Name :
Reg. No. :
Subject : PHP PROGRAMMING
Subject Code : (SCSJS4P)
MADURAI KAMARAJAR UNIVERSITY
DEVANGA ARTS COLLEGE
Reaccredited and Graded ‘A’ by NAAC
ARUPPUKOTTAI - 626101.
NAME :
CLASS : II B.Sc. (CS)
REGISTER No. :
This is certified that the bonafide record of
PRACTICAL WORK
Done by Reg. No.
in the Computer Laboratory.
Head of the Department Staff-In-Charge
Submitted for Autonomous Practical Examination APRIL2022
held
on at Devanga Arts College, Aruppukottai.
Internal Examiner External Examiner
CONTENTS
PAGE
EX.NO. DATE TITLE SIGN
NO.
1 Swapping of Two Numbers
2 Simple Interest Calculation
3 Biggest among three numbers
4 Multiplication Table
5 Arithmetic operations
6 String Operations
7 Factorial Calculation using Function
8 Login form
9 Class and Object
10 Fibonacci series
11 Odd or Even
12 Palindrome or not
13 Reusing Code
14 Associative Array
15 Online Quiz
SWAPPING OF TWO NUMBERS
Ex.no: 1
Date:
AIM
To write a PHP program for Swapping of Two Numbers.
PROGRAM:
<html>
<head>
<title>Swapping of Two Numbers</title>
</head>
<body>
<h2>SWAPPING OF TWO NUMBERS</h2>
<form name="fm" method="POST" action="<?php $_PHP_SELF?>">
Enter First Number: <input type="text" name="num1"> <br><br>
Enter Second Number: <input type="text" name="num2"> <br><br>
<input type="submit" value="Accept">
<input type="reset" value="Clear">
</form>
</body>
</html>
<?php
if(isset($_POST['num1']) && isset($_POST['num2']))
{
$a=$_POST['num1'];
$b=$_POST['num2'];
echo "<br>BEFORE SWAPPING : ".$a." ".$b."<br>";
$a=$a+$b;
$b=$a-$b;
$a=$a-$b;
echo "<br>AFTER SWAPPING : ".$a." ".$b."<br>";
}
?>
OUTPUT:
RESULT:
Thus the above PHP program for Swapping of Two Numbers was
executed and the output was verified successfully.
SIMPLE INTEREST CALCULATION
Ex.no: 2
Date:
AIM:
To write a PHP program for Simple Interest Calculation.
PROGRAM:
<html>
<head>
<title>Simple Interest Calculation</title>
</head>
<body>
<h2>SIMPLE INTEREST CALCULATION</h2>
<form name="fm" method="POST" action="<?php $_PHP_SELF?>">
Enter Principle Amount: <input type="text" name="prin"> <br><br>
Enter Number of Years: <input type="text" name="year"> <br><br>
Enter Rate of Interest(%): <input type="text" name="inte"> <br><br>
<input type="submit" value="Accept">
<input type="reset" value="Clear">
</form>
</body>
</html>
<?php
if(isset($_POST['prin']) && isset($_POST['year']) && isset($_POST['inte']))
{
$p=$_POST['prin'];
$n=$_POST['year'];
$r=$_POST['inte'];
$si=$p*$n*$r/100;
echo "<br>SIMPLE INTEREST IS : ".$si;
}
?>
OUTPUT:
RESULT:
Thus the above PHP program for Simple Interest Calculation was
executed and the output was verified successfully.
BIGGEST AMONG THREE NUMBERS
Ex.no: 3
Date:
AIM:
To write a PHP program for find Biggest Among Three Numbers.
PROGRAM:
<html>
<head>
<title>Biggest Among Three Numbers</title>
</head>
<body>
<h2>Biggest Among Three Numbers</h2>
<form name="fm" method="POST" action="<?php $_PHP_SELF?>">
Enter First Number: <input type="text" name="num1"><br><br>
Enter Second Number: <input type="text" name="num2"><br><br>
Enter Third Number: <input type="text" name="num3">
<input type="submit" value="Accept">
<input type="reset" value="Clear">
</form>
</body>
</html>
<?php
if(isset($_POST['num1']) && isset($_POST['num2']) && isset($_POST['num3']))
{
$n1=$_POST['num1'];
$n2=$_POST['num2'];
$n3=$_POST['num3']; if($n1>$n2 && $n1>$n3)
echo "<br>First Number is BIGGEST:".$n1; else if($n2>$n3)
echo "<br>Second Number is BIGGEST:".$n2; else
echo "<br>Third Number is BIGGEST:".$n3;
}
?>
OUTPUT:
RESULT:
Thus the above PHP program for find Biggest Among Three Numbers was
executed and the output was verified successfully.
MULTIPLICATION TABLE
Ex.no: 4
Date:
AIM:
To write a PHP program for display Multiplication Table.
PROGRAM:
<html>
<head>
<title>Multiplication Table</title>
</head>
<body>
<h2>MULTIPLICATION TABLE</h2>
<form name="fm" method="POST" action="<?php $_PHP_SELF?>"> Enter Table
Number: <input type="text" name="num1"> <br><br> Enter Ending Number: <input
type="text" name="num2"> <br><br>
<input type="submit" value="Accept">
<input type="reset" value="Clear">
</form>
</body>
</html>
<?php
if(isset($_POST['num1']) && isset($_POST['num2']))
{
$t=$_POST['num1'];
$n=$_POST['num2'];
echo "<br>MULTIPLICATION TABLE IS : <br>" ;
for($i=1;$i<=$n;$i++)
{
$f=$i*$t;
echo $i."*".$t."=".$f."<br>";
}
}
?>
OUTPUT:
RESULT:
Thus the above PHP program for display Multiplication Table was executed and
the output was verified successfully.
ARITHMETIC OPERATIONS
Ex.no: 5
Date:
AIM:
To write a PHP program for Arithmetic operations.
PROGRAM:
<html>
<head>
<title>Arithmetic Operations</title>
</head>
<body>
<h2>Arithmetic Operations</h2>
<form name="fm" method="POST" action="<?php $_PHP_SELF?>">
Enter First Number: <input type="text" name="num1"><br><br>
Enter Second Number: <input type="text" name="num2"><br><br>
Select the Operation:
<select name = "choice">
<option value="0">Select</option>
<option value="1">Addition</option>
<option value="2">Subtraction</option>
<option value="3">Multiplication</option>
<option value="4">Division</option>
<option value="5">Modulus</option>
</select>
<input type="submit" value="Accept">
<input type="reset" value="Clear">
</form>
</body>
</html>
<?php
if(isset($_POST['num1']) && isset($_POST['num2']))
{
$n1=$_POST['num1'];
$n2=$_POST['num2'];
$ch=$_POST['choice']; switch($ch)
{
case 1:
$a=$n1+$n2;
echo "<br>Addition is: ".$a; break;
case 2:
$a=$n1-$n2;
echo "<br>Subtraction is: ".$a; break;
case 3:
$a=$n1*$n2;
echo "<br>Multiplication is: ".$a; break;
case 4:
$a=$n1/$n2;
echo "<br>Division is: ".$a; break;
case 5:
$a=$n1%$n2;
echo "<br>Modulus is: ".$a; break;
default:
echo "<br>Invalid Choice";
}
}
?>
OUTPUT:
RESULT:
Thus the above PHP program for Arithmetic operations was executed and the
output was verified successfully.
STRING OPERATIONS
Ex.no: 6
Date:
AIM:
To write a PHP program for String Operations.
PROGRAM:
<html>
<head><title>String Operations</title></head>
<body bgcolor="pink">
<form name="fm" method="POST" action="<?php $_PHP_SELF?>">
<h1><u>STRING OPERATIONS</u></h1>
Enter First string:<input type="text" name="str1"><br><br> Enter Second string:<input
type="text" name="str2"><br><br>
<br>
<input type="submit" name="Accept">
<input type="reset" value="Clear">
</form></body></html>
<?php
if(isset($_POST['str1']) && isset($_POST['str2']))
{
$s1=$_POST['str1'];
$s2=$_POST['str2'];
echo"<br>First string is:".$s1;
echo"<br>Second string is:".$s2;
echo "<br><br>";
echo"<br>Length of ".$s1." is ".strlen($s1);
echo"<br>Substring of ".$s1." is ".substr($s1,1,4);
echo"<br>Trim of ".$s1." is ".trim($s1);
if(strcmp($s1,$s2)>0)
echo"<br>".$s1." is greater than ".$s2;
else if(strcmp($s1,$s2)<0)
echo"<br>".$s2." is greater than ".$s1;
else
echo"<br>".$s1." and ".$s2." is equal";
echo"<br>Upper Case of ".$s1." is ".strtoupper($s1);
echo"<br>Lower Case of ".$s1." is ".strtolower($s1);
echo"<br>Concatenation is:".$s1." ".$s2;
}
?>
OUTPUT:
RESULT:
Thus the above PHP program for String Operations was executed and the output was
verified successfully.
FACTORIAL CALCULATION
Ex.no: 7
Date:
AIM:.
To write a PHP program Factorial Calculation using Function.
PROGRAM:
<html>
<head>
<title>Factorial Calculation</title>
</head>
<body>
<h2>FACTORIAL CALCULATION</h2>
<form name="fm" method="POST" action="<?php $_PHP_SELF?>">
Enter Any Number: <input type="text" name="num">
<input type="submit" value="Accept">
<input type="reset" value="Clear">
</form>
</body>
</html>
<?php if(isset($_POST['num']))
{
$n=$_POST['num'];
$ans=fact($n);
echo "Factorial value is:".$ans;
}
function fact($n)
{
$f=1; for($i=1;$i<=$n;$i++)
$f=$f*$i; return $f;
}
?>
OUTPUT:
RESULT:
Thus the above PHP program Factorial Calculation using Function was executed and the
output was verified successfully.
LOGIN FORM
Ex.no: 8
Date:
AIM:
To write a PHP program for Login Form.
PROGRAM:
Log.php
<html>
<head>
<title>Login Form</title>
</head>
<body>
<h2>LOGIN FORM!</h2>
<form name="login" method="post" action="check.php">
User Name : <input type="text" name="user" maxlength="6"> <br><br>
Password :<input type="password" name="pass" maxlength="6"><br><br>
<input type="submit" value="SUBMIT">
<input type="reset" value="CLEAR">
</body>
</html>
check.php
<?php
if(isset($_POST['user']) && isset($_POST['pass']))
{
$u=$_POST['user'];
$p=$_POST['pass'];
echo "<br><br>USER NAME IS: ".$u;
echo "<br><br>PASSWORD IS : ".$p;
if($u==$p)
echo "<br><br>VALID USER : ".$u;
else
echo "<br><br>INVALID USER : ".$u;
}
?>
OUTPUT:
RESULT:
Thus the above PHP program for Login Form was executed and the output was
verified successfully.
CLASS AND OBJECT
Ex.no: 9
Date:
AIM:
To write a PHP program for CLASS AND OBJECT.
PROGRAM:
<html>
<head>
<title>Class & Object</title>
</head>
<body>
<h1>CLASS AND OBJECT</h1>
</body>
</html>
<?php
class MyClass
{
function disp()
{
echo "Welcome to PHP";
}
}
$obj = new MyClass();
$obj->disp();
?>
OUTPUT:
RESULT:
Thus the above PHP program for CLASS AND OBJECT was executed and the
output was verified successfully.
FIBONACCI SERIES
Ex.no: 10
Date:
AIM:
To write a PHP program for Fibonacci series.
PROGRAM:
<html>
<head>
<title>Fibonacci Series</title>
</head>
<body>
<h2>Fibonacci Series</h2>
<form name="fm" method="POST" action="<?php $_PHP_SELF?>">
Enter Any Number: <input type="text" name="num">
<input type="submit" value="Accept">
<input type="reset" value="Clear">
</form>
</body>
</html>
<?php if(isset($_POST['num']))
{
$n=$_POST['num'];
$f1=-1;
$f2=1;
echo"Fibonacci series is:<br>"; for($i=0;$i<$n;$i++)
{
$f3=$f1+$f2;
$f1=$f2;
$f2=$f3; echo'<br>'.$f3;
}
}
?>
OUTPUT:
RESULT:
Thus the above PHP program for Voting Eligibility was executed and the output was verified
successfully.
ODD OR EVEN
Ex.no: 11
Date:
AIM:
To write a PHP program for check given number is ODD or EVEN.
PROGRAM:
<html>
<head>
<title>ODD or EVEN</title>
</head>
<body>
<h2>ODD or EVEN</h2>
<form name="fm" method="POST" action="<?php $_PHP_SELF?>">
Enter Any Number: <input type="text" name="num">
<input type="submit" value="Accept">
<input type="reset" value="Clear">
</form>
</body>
</html>
<?php if(isset($_POST['num']))
{
$n=$_POST['num'];
if($n%2==0)
echo "<br>Given Number is EVEN:".$n;
else
echo "<br>Given Number is ODD:".$n;
}
?>
OUTPUT:
RESULT:
Thus the above PHP program for check given number is ODD or EVEN was
executed and the output was verified successfully.
PALINDROME OR NOT
Ex.no: 12
Date:
AIM:
To write a PHP program for check the given string is Palindrome or Not.
PROGRAM:
<html>
<head>
<title>Palindrome or Not</title>
</head>
<body>
<h2>PALINDROME OR NOT</h2>
<form name="fm" method="POST" action="<?php $_PHP_SELF?>">
Enter Any String: <input type="text" name="str">
<input type="submit" value="Accept">
<input type="reset" value="Clear">
</form>
</body>
</html>
<?php if(isset($_POST['str']))
{
$s=$_POST['str'];
$rev = strrev($s);
echo '<br>Reverse value is: '.$rev.'<br>';
if($s == $rev)
echo "<span style='color:green'>Yes! the value is Palindrome!</span>";
else
echo "<span style='color:red'>No! the value is not a Palindrome!</span>";
}
?>
OUTPUT:
RESULT:
Thus the above PHP program for check the given string is Palindrome or Not was
executed and the output was verified successfully.
REUSING CODE
Ex.no: 13
Date:
AIM:
To write a PHP program for Reusing Code.
PROGRAM:
//one.php
<?php
echo "PHP is a Open Source <br />";
?>
//two.php
<?php
echo "PHP is a Dynamic Web Page Creator<br />";
?>
//fin.php
<html>
<head>
<title>Require and Include</title>
</head>
<body>
<h1>Require and Include</h1>
</body>
</html>
<?php
echo "Starts...<br>";
require('one.php');
include('two.php');
echo "Ends ";
?>
OUTPUT:
RESULT:
Thus the above PHP program for Reusing Code was executed and the output was
verified successfully.
ASSOCIATIVE ARRAY
Ex.no: 14
Date:
AIM:
To write a PHP program for Associative Array.
PROGRAM:
<html>
<head>
<title>Associative Array</title>
</head>
<body>
<h1>ASSOCIATIVE ARRAY</h1>
</body>
</html>
<?php
$student = array("Maths"=>95, "Physics"=>90, "Chemistry"=>96, "English"=>93,
"Computer"=>98);
echo "Marks for Student is:<br>";
foreach ($student as $subject => $marks){ echo $subject.":".$marks."<br>";
}
?>
OUTPUT:
RESULT:
Thus the above PHP program for Associative Array was executed and the
output was verified successfully.
ONLINE QUIZ
Ex.no: 15
Date:
AIM:
To write a PHP program for Online Quiz.
PROGRAM:
<html>
<head><title>Online Quiz</title></head>
<body bgcolor="pink">
<h2>Online Quiz</h2>
<form name="fm" method="POST" action="<?php $_PHP_SELF ?>">
<br>
1. National Animal<br>
<input type="radio" name="ques1" value="1.1">Tiger
<input type="radio" name="ques1" value="1.2">Lion
<input type="radio" name="ques1" value="1.3">Elephant<br><br>
2. National Flower<br>
<input type="radio" name="ques2" value="2.1">Lotus
<input type="radio" name="ques2" value="2.2">Jasmine
<input type="radio" name="ques2" value="2.3">Lily<br><br>
3. National Game<br>
<input type="radio" name="ques3" value="3.1">Hockey
<input type="radio" name="ques3" value="3.2">Cricket
<input type="radio" name="ques3" value="3.3">FootBall<br><br>
4. IDE means<br>
<input type="radio" name="ques4" value="4.1">Integrated Development Environment
<input type="radio" name="ques4" value="4.2">Integrated Digital Environment
<input type="radio" name="ques4" value="4.3">Indian Development
Environment<br><br>
5. WWW means<br>
<input type="radio" name="ques5" value="5.1">World Wide Web
<input type="radio" name="ques5" value="5.2">World Web Wide
<input type="radio" name="ques5" value="5.3">World Web Window<br><br>
<input type="submit">
</form>
</body>
</html>
<?php
if(isset($_POST['ques1']) && $_POST['ques2'] && $_POST['ques3']&&
$_POST['ques4']&& $_POST['ques5'] )
{
$mk=0;
$a=$_POST['ques1'];
$b=$_POST['ques2'];
$c=$_POST['ques3'];
$d=$_POST['ques4'];
$e=$_POST['ques5'];
if($a == '1.1')
{
$mk=$mk+1;
}
if($b=='2.1')
{
$mk=$mk+1;
}
if($c == '3.1')
{
$mk=$mk+1;
}
if($d=='4.1')
{
$mk=$mk+1;
}
if($e=='5.1')
{
$mk=$mk+1;
}
if($mk==0)
echo "No Marks";
else
echo "You have scored $mk marks";
}
?>
OUTPUT:
RESULT:
Thus the above PHP program for Online Quiz was executed and the output was verified
successfully.