Uploaded by Shubham Sharma

Practical PHP

advertisement
Program 1: Calculator
<!DOCTYPE html>
<?php
$a_shub = $_POST["number1"];
$b_shub = $_POST["number2"];
$opr_shub = $_POST["opr"];
$res_shub = 0;
switch ($opr_shub) {
case "add":
$res_shub = $a_shub + $b_shub;
break;
case "sub":
$res_shub = $a_shub - $b_shub;
break;
case "div":
$res_shub = $a_shub / $b_shub;
break;
}
?>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Program 1</title>
<style>
.frm {
border: 1px solid #000;
padding: 20px;
width: 25%;
min-width: 200px;
margin: auto;
background-color: #adadad;
}
.lbl {
1
font-size: 20px;
font-weight: bold;
margin-left: 20px;
}
.inpt {
font-size: 20px;
color: blue;
margin-left: 20px;
margin-top: 4px;
padding-left: 5px;
}
.frm_control {
margin-top: 10px;
}
.btn {
width: 100px;
height: 40px;
background-color: blue;
font-size: 20px;
color: cornsilk;
margin-left: 20px;
}
</style>
</head>
<body>
<h1 style="text-align:center;">Program to perform basic mathematical
operations</h1>
<div class="frm">
<article>
<h2 style="text-align:center;backgroundcolor:red;padding:5px;">Calculator</h2>
</article>
<form method="post" action="result.php">
<div class="frm_control">
2
<label class="lbl">Enter Number 1</label><br>
<input class="inpt" value="<?php echo isset($a_shub) ? $a_shub : '';
?>" type="number">
</div>
<div class="frm_control">
<label class="lbl">Enter Number 2</label><br>
<input value="<?php echo isset($b_shub) ? $b_shub : ''; ?>"
class="inpt" type="number">
</div>
<div class="frm_control">
<label class="lbl">Result</label><br>
<input value="<?php echo isset($res_shub) ? $res_shub : ''; ?>"
class="inpt" type="number" name="result">
</div>
<br>
<div class="frm_control">
<a href="program1.php">Click me</a>
</div>
</form>
</div>
</body>
</html>
Program 2: Area Information of the desired diagram
<!DOCTYPE html>
<?PHP
if (isset($_POST["submit"])) {
$area_shub = isset($_POST["area"]) ? $_POST["area"] : 0;
$num1_shub = isset($_POST["number1"]) ? $_POST["number1"] : 0;
3
$num2_shub = isset($_POST["number2"]) ? $_POST["number2"] : 0;
$pi_shub = 3.141;
switch ($area_shub) {
case "rectangle":
$a_shubr = $num1_shub * $num2_shub;
break;
case "circle":
$a_shubr = $pi_shub * $num1_shub * $num1_shub;
break;
case "triangle":
$a_shubr = (0.5) * $num1_shub * $num2_shub;
break;
}
}
?>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Program 1</title>
<style>
.frm {
border: 1px solid #000;
padding: 20px;
width: 25%;
min-width: 200px;
margin: auto;
background-color: #adadad;
}
.lbl {
font-size: 20px;
font-weight: bold;
margin-left: 20px;
}
4
.inpt {
font-size: 20px;
color: blue;
margin-left: 20px;
margin-top: 4px;
padding-left: 5px;
}
.frm_control {
margin-top: 10px;
}
.btn {
width: 100px;
height: 40px;
background-color: blue;
font-size: 20px;
color: cornsilk;
margin-left: 20px;
}
</style>
</head>
<body>
<h1 style="text-align:center;">Area Information of the desired
diagram!</h1>
<div class="frm">
<article>
<h2 style="text-align:center;background-color:red;padding:5px;">Area
of <?php echo $area_shub; ?></h2>
</article>
<form method="post" action="#">
<div class="frm_control">
<label class="lbl">Dimension 1</label><br>
<input class="inpt" type="number" value="<?php echo
isset($num1_shub) ? $num1_shub : 0; ?>">
</div>
<div class="frm_control">
5
<label class="lbl">Dimension 2</label><br>
<input value="<?php echo isset($num1_shub) ? $num2_shub : 0; ?>"
class="inpt" type="number" name="number2">
</div>
<div class="frm_control">
<label class="lbl">Area</label><br>
<input class="inpt" type="number" value="<?php echo
isset($a_shubr) ? $a_shubr : 0; ?>" name="ar">
</div>
<br>
<div class="frm_control">
<input type="submit" name="submit" class="btn" value="submit">
<br>
<a href="program2.php">Main screen</a>
</div>
</div>
</form>
</div>
</body>
</html>
Program 3: Program to Calculate the roots of a quadratic
equation
<?php
$a_shub = $_POST["a"];
$b_shub = $_POST["b"];
$c_shub = $_POST["c"];
$disc_shub = $b_shub * $b_shub - 4 * $a_shub * $c_shub;
$msg_shub = "";
if ($disc_shub < 0) {
$msg_shub = "Roots are imaginary!";
} elseif ($disc_shub == 0) {
$rts = -$b_shub / (2 * $a_shub);
6
$msg_shub = "Roots are Equal! <br>";
$msg_shub = $msg_shub . "Each root= " . $rts;
} else {
$rts1 = (-$b_shub - sqrt($disc_shub)) / (2 * $a_shub);
$rts2 = (-$b_shub + sqrt($disc_shub)) / (2 * $a_shub);
$msg_shub = "Roots are Real!<br>";
$msg_shub = $msg_shub . "Root1 = " . $rts1 . " ";
$msg_shub = $msg_shub . "Root2 = " . $rts2;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Program 1</title>
<style>
.frm {
border: 1px solid #000;
padding: 20px;
width: 25%;
min-width: 200px;
margin: auto;
background-color: #adadad;
height: 400px;
}
.lbl {
font-size: 20px;
font-weight: bold;
margin-left: 20px;
}
.lblw {
font-size: 20px;
font-weight: bold;
margin-left: 20px;
color: #f00;
7
}
.inpt {
font-size: 20px;
color: blue;
margin-left: 20px;
margin-top: 4px;
padding-left: 5px;
}
.frm_control {
margin-top: 10px;
}
.btn {
width: 100px;
height: 40px;
background-color: blue;
font-size: 20px;
color: cornsilk;
margin-left: 20px;
}
</style>
</head>
<body>
<h1 style="text-align:center;">Program to Calculate the roots of a quadratic
equation</h1>
<div class="frm">
<article>
<h2 style="text-align:center;background-color:red;padding:5px;">Roots
of Quad Eq.</h2>
<h3>ax<sup>2</sup>+bx+c=0</h3>
<h3><?php echo $a_shub; ?>x<sup>2</sup>+<?php echo "(" . $b_shub
. ")"; ?>x+<?php echo "(" . $c_shub . ")"; ?>=0</h3>
</article>
<form action="result.php" method="post">
<label class="lbl">The value of A: <?php echo $a_shub;
?></label><br>
<br>
<label class="lbl">The value of B: <?php echo $b_shub;
?></label><br>
8
<br>
<label class="lbl">The value of C: <?php echo $c_shub;
?></label><br>
<br>
<label class="lbl">The value of Disc: <?php echo $disc_shub;
?></label><br>
<br>
<label class="lblw">Message : <?php echo $msg_shub; ?></label><br>
<div class="frm_control">
<a href="index.php">Back</a>
</div>
</form>
</div>
<br>
</body>
</html>
Program 4: Greatest of Two Number
PHP:
<?php
$a_shub = $_POST["number1"];
$b_shub = $_POST["number2"];
$g1_shub = 0;
$g1_shub = ($a_shub>$b_shub)?$a_shub:$b_shub;
echo "The greatest number is: ".$g1_shub;
?>
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
9
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<?php
include("../js.php");
include("../style.php");
?>
<style>
.frm{
border:1px solid #000;
width:30%;
min-width:450px;
padding:10px;
margin:auto;
}
</style>
</head>
<body>
<div class="bg-danger p-4 mb-5">
<h1 class="text-center text-light">Greatest of three numbers</h1>
</div>
<div class="frm">
<form method="post" action="practical1.php">
<div class="mb-3">
<label class="form-label">Number 1</label>
<input type="number" class="form-control" id="number1"
name="number1">
</div>
<div class="mb-3">
<label class="form-label">Number 2</label>
<input type="number" class="form-control" id="number2"
name="number2">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
10
</form>
</div>
</body>
</html>
Program 5: Greatest of Three Number
PHP:
<?php
$a_shub = $_POST["number1"];
$b_shub = $_POST["number2"];
$c_shub = $_POST["number3"];
$g1_shub = 0;
$g2_shub = 0;
$g1_shub = ($a_shub>$b_shub)?$a_shub:$b_shub;
$g2_shub = ($g1_shub>$c_shub )?$g1_shub:$c_shub ;
echo "The greatest number is: ".$g2_shub;
?>
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
11
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<?php
include("../js.php");
include("../style.php");
?>
<style>
.frm{
border:1px solid #000;
width:30%;
min-width:450px;
padding:10px;
margin:auto;
}
</style>
</head>
<body>
<div class="bg-danger p-4 mb-5">
<h1 class="text-center text-light">Greatest of three numbers</h1>
</div>
<div class="frm">
<form method="post" action="practical1.php">
<div class="mb-3">
<label class="form-label">Number 1</label>
<input type="number" class="form-control" id="number1"
name="number1">
</div>
<div class="mb-3">
<label class="form-label">Number 2</label>
<input type="number" class="form-control" id="number2"
name="number2">
</div>
<div class="mb-3">
<label class="form-label">Number 3</label>
12
<input type="number" class="form-control" id="number3"
name="number3">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</body>
</html>
Program 6: Program to print Sum of first n Natural Numbers
PHP:
<?php
$n_shub = $_POST["a"];
$s_shub=0;
for($i_shub=1;$i_shub<=$n_shub;$i_shub++)
{
$s_shub = $s_shub+$i_shub;
}
echo "<h1 style='text-align:center;color:#f00;'>Sum of ".$n_shub." Natural
numbers: ". $s_shub."</h1>";
echo "<br><div style='text-align:center;'><a
href='index.php'>BACK</a></div>";
?>
HMTL:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Program 1</title>
<style>
.frm{
border:1px solid #000;
13
padding:20px;
width: 25%;
min-width: 200px;
margin:auto;
background-color: #adadad;
height:250px;
}
.lbl{
font-size:20px;
font-weight: bold;
margin-left:20px;
}
.inpt{
font-size:20px;
color:blue;
margin-left:20px;
margin-top:4px;
padding-left:5px;
}
.frm_control{
margin-top:10px;
}
.btn{
width:100px;
height:40px;
background-color: blue;
font-size:20px;
color:cornsilk;
margin-left: 20px;
}
</style>
</head>
<body>
<h1 style="text-align:center;">Program to print Sum of first n Natural
Numbers</h1>
<div class="frm">
<article>
14
<h2 style="text-align:center;backgroundcolor:red;padding:5px;">Natural Number Sum</h2>
</article>
<form action="result.php" method="post">
<label class="lbl">Enter value of n</label><br>
<input value=0 class="inpt" type="number" name="a">
<br>
<div class="frm_control">
<input type="submit" name="submit" class="btn" value="submit">
</div>
</form>
</div>
<br>
</body>
</html>
15
Program7: Program to print n numbers of Fibonacci Series
PHP:
<?php
$n_shub = $_REQUEST["n"];
$a_shub = 0;
$b_shub = 1;
echo"<div style='margin:auto;width:60%;border:1px solid
#000;background-color:#f00;'>";
echo"<h1 style='text-align:center;'>The result of desired Fibonacci series
program is: </h1>";
echo"<div style='text-align:center;'><h2>";
if($n_shub<=0)
{
echo"Not a valid input!";
}
elseif($n_shub==1){
echo "0";
}
elseif($n_shub==2)
{
echo"$a_shub, $b_shub";
}
else{
echo"$a_shub, $b_shub, ";
$c = $a_shub+$b_shub;
for($i=3;$i<=$n_shub;$i++)
{
echo $c.", ";
$a_shub=$b_shub;
$b_shub=$c;
$c=$a_shub+$b_shub;
}
}
16
echo"</h2></div>";
echo"</div>";
?>
HMTL:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Program 1</title>
<style>
.frm{
border:1px solid #000;
padding:20px;
width: 25%;
min-width: 200px;
margin:auto;
background-color: #adadad;
height:250px;
}
.lbl{
font-size:20px;
font-weight: bold;
margin-left:20px;
}
.inpt{
font-size:20px;
color:blue;
margin-left:20px;
margin-top:4px;
padding-left:5px;
}
.frm_control{
margin-top:10px;
}
.btn{
17
width:100px;
height:40px;
background-color: blue;
font-size:20px;
color:cornsilk;
margin-left: 20px;
}
</style>
</head>
<body>
<h1 style="text-align:center;">Program to print n numbers of Fibonacci
Series</h1>
<div class="frm">
<article>
<h2 style="text-align:center;background-color:red;padding:5px;">Print
Fibonacci Series</h2>
</article>
<form action="result.php" method="post">
<label class="lbl">Enter value of n</label><br>
<input value=0 class="inpt" type="number" name="n">
<br>
<div class="frm_control">
<input type="submit" name="submit" class="btn" value="submit">
</div>
</form>
</div>
<br>
</body>
</html>
Program 8: Program to find the Factorial of a number
PHP:
<?php
18
$n_shub = $_POST["a"];
$f_shub=1;
if($n_shub==0)
{
$f_shub= 1;
$msg = "The factorial of $n_shub = $f_shub";
}else if($n_shub<0){
$msg= "Factorial of negative number not possible!";
}
else{
for($i=1;$i<=$n_shub;$i++)
{
$f_shub = $f_shub*$i;
}
$msg = "The factorial of $n_shub = $f_shub";
}
echo "<h1 style='text-align:center;color:#f00;'>$msg</h1>";
echo "<br><div style='text-align:center;'><a
href='index.php'>BACK</a></div>";
?>
HMTL:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Program 1</title>
<style>
.frm{
border:1px solid #000;
padding:20px;
width: 25%;
min-width: 200px;
margin:auto;
background-color: #adadad;
height:250px;
19
}
.lbl{
font-size:20px;
font-weight: bold;
margin-left:20px;
}
.inpt{
font-size:20px;
color:blue;
margin-left:20px;
margin-top:4px;
padding-left:5px;
}
.frm_control{
margin-top:10px;
}
.btn{
width:100px;
height:40px;
background-color: blue;
font-size:20px;
color:cornsilk;
margin-left: 20px;
}
</style>
</head>
<body>
<h1 style="text-align:center;">Program to find the Factorial of a
number</h1>
<div class="frm">
<article>
<h2 style="text-align:center;backgroundcolor:red;padding:5px;">Factorial of a number</h2>
</article>
<form action="result.php" method="post">
<label class="lbl">Enter value of n</label><br>
<input value=0 class="inpt" type="number" name="a">
20
<br>
<div class="frm_control">
<input type="submit" name="submit" class="btn" value="submit">
</div>
</form>
</div>
<br>
</body>
</html>
Program 9: Program to print prime numbers within a specific
range
PHP:
<?php
$a_shub = isset($_POST["a"])?$_POST["a"]:0;
$b_shub = isset($_POST["b"])?$_POST["b"]:0;
$n_shub = $a_shub;
21
echo "<div style='margin:auto;border:1px solid
#000;width:40%;padding:10px;'>";
echo"<h1 style='padding:10px;background-color:#f00;color:#fff;textalign:center;'>Prime numbers between $a_shub and $b_shub </h1>";
echo"<h2 style='text-align:center;'>";
while($n_shub<$b_shub)
{
top:
for($i=2;$i<$n_shub;$i++)
{
if($n_shub%$i==0)
{
$n_shub++;
goto top;
}
}
if($n_shub<$b_shub)
{
echo "<br>".$n_shub;
}
$n_shub++;
}
echo"</h2>";
echo"</div>";
?>
HMTL:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Program 1</title>
<style>
.frm{
border:1px solid #000;
padding:20px;
22
width: 25%;
min-width: 200px;
margin:auto;
background-color: #adadad;
height:250px;
}
.lbl{
font-size:20px;
font-weight: bold;
margin-left:20px;
}
.inpt{
font-size:20px;
color:blue;
margin-left:20px;
margin-top:4px;
padding-left:5px;
}
.frm_control{
margin-top:10px;
}
.btn{
width:100px;
height:40px;
background-color: blue;
font-size:20px;
color:cornsilk;
margin-left: 20px;
}
</style>
</head>
<body>
<h1 style="text-align:center;">Program to print prime numbers within a
specific range</h1>
<div class="frm">
<article>
<h2 style="text-align:center;background-color:red;padding:5px;">Print
Prime numbers</h2>
23
</article>
<form action="result.php" method="post">
<label class="lbl">Enter value of first number</label><br>
<input value=0 class="inpt" type="number" name="a">
<br><br>
<label class="lbl">Enter value of second number</label><br>
<input value=0 class="inpt" type="number" name="b">
<br>
<div class="frm_control">
<input type="submit" name="submit" class="btn" value="submit">
</div>
</form>
</div>
<br>
</body>
</html>
Program 10: PHP Program To check triangle is Isosceles triangle
or Not
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP Program To check triangle is Isosceles triangle or Not </title>
</head>
<body>
24
<form method="post">
<table border="0">
<tr>
<td> <input type="text" name="num1" value="" placeholder="Enter
length of 1st side" />
</td>
</tr>
<tr>
<td> <input type="text" name="num2" value="" placeholder="Enter
length of 2nd side" />
</td>
</tr>
<tr>
<td> <input type="text" name="num3" value="" placeholder="Enter
length of 3rd side" />
</td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Submit" />
</td>
</tr>
</table>
</form>
<?php
if (isset($_POST['submit'])) {
$a_shub = $_POST['num1'];
$b_shub = $_POST['num2'];
$c_shub = $_POST['num3'];
echo "Given sides : " . $a_shub . " " . $b_shub . " " . $c_shub . "</br>";
if (($a_shub == $b_shub) || ($b_shub == $c_shub) || ($c_shub ==
$a_shub)) {
echo ("Isosceles triangle");
}
25
else{
echo("Not an Isosceles triangle");
}
return 0;
}
?>
</body>
</html>
Program 11:
<?php
$n_shub = $_POST["a"];
$table_shub = 0;
for ($i_shub = 1; $i_shub <= 10; $i_shub++) {
$table_shub = $i_shub * $n_shub;
echo "".$n_shub." x ".$i_shub." = ". $table_shub . "<br>";
}
echo "<br><div><a href='index.php'>BACK</a></div>";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
26
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Program 1</title>
<style>
.frm{
border:1px solid #000;
padding:20px;
width: 25%;
min-width: 200px;
margin:auto;
background-color: #adadad;
height:250px;
}
.lbl{
font-size:20px;
font-weight: bold;
margin-left:20px;
}
.inpt{
font-size:20px;
color:blue;
margin-left:20px;
margin-top:4px;
padding-left:5px;
}
.frm_control{
margin-top:10px;
}
.btn{
width:100px;
height:40px;
background-color: blue;
font-size:20px;
color:cornsilk;
margin-left: 20px;
}
</style>
</head>
<body>
<h1 style="text-align:center;">Program to print Table of number</h1>
27
<div class="frm">
<article>
<h2
style="text-align:center;backgroundcolor:red;padding:5px;">Number </h2>
</article>
<form action="result.php" method="post">
<label class="lbl">Enter number</label><br>
<input value=0 class="inpt" type="number" name="a">
<br>
<div class="frm_control">
<input type="submit" name="submit" class="btn" value="submit">
</div>
</form>
</div>
<br>
</body>
</html>
Program 12:
<!DOCTYPE html>
<html lang="en">
<?php
function countV($str_shub)
{
preg_match_all('/[aeiou]/i', $str_shub, $matches);
return count($matches[0]);
}
if(isset($_POST))
{
$txt = isset($_POST["txt"])?$_POST["txt"]:"";
$cntv = countV($txt);
}
?>
<head>
<meta charset="UTF-8">
28
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Program 1</title>
<style>
.frm{
border:1px solid #000;
padding:20px;
width: 25%;
min-width: 200px;
margin:auto;
background-color: #adadad;
height:250px;
}
.lbl{
font-size:20px;
font-weight: bold;
margin-left:20px;
}
.inpt{
font-size:20px;
color:blue;
margin-left:20px;
margin-top:4px;
padding-left:5px;
}
.frm_control{
margin-top:10px;
}
.btn{
width:100px;
height:40px;
background-color: blue;
font-size:20px;
color:cornsilk;
margin-left: 20px;
}
</style>
</head>
29
<body>
<h1 style="text-align:center;">Program to count the number of vowels</h1>
<div class="frm">
<article>
<h2 style="text-align:center;backgroundcolor:red;padding:5px;">Program to count the vowels in the string</h2>
</article>
<form action="#" method="post">
<label class="lbl">Enter the String</label><br>
<input autocomplete="off" class="inpt" type="text" name="txt">
<br><br>
<div class="frm_control">
<input type="submit" name="submit" class="btn" value="submit">
</div>
</form>
</div>
<div style="margin:auto; text-align:center;">
<h2>Entered String is: <?php echo $txt;?> </h2>
<h2>Number of Vowels: <?php echo $cntv;?></h2>
</div>
<br>
</body>
</html>
30
Program 13:
<?php
$txt_shub = isset($_POST['txt'])?$_POST['txt']:"";
$txt_shub_rev = strtolower(strrev($txt_shub));
if($txt_shub==$txt_shub_rev)
{
$msg="Entered String is Palindrome!";
}
else{
$msg="Entered String is not Palindrome!";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Program 1</title>
<style>
.frm{
border:1px solid #000;
padding:20px;
width: 25%;
min-width: 200px;
margin:auto;
background-color: #adadad;
31
}
.lbl{
font-size:20px;
font-weight: bold;
margin-left:20px;
}
.inpt{
font-size:20px;
color:blue;
margin-left:20px;
margin-top:4px;
padding-left:5px;
}
.frm_control{
margin-top:10px;
}
.btn{
width:100px;
height:40px;
background-color: blue;
font-size:20px;
color:cornsilk;
margin-left: 20px;
}
</style>
</head>
<body>
<h1 style="text-align:center;">Program to check whether the string is
palindrome or not</h1>
<div class="frm">
<article>
<h2 style="text-align:center;backgroundcolor:red;padding:5px;">Palindrome String Check</h2>
</article>
<form action="result.php" method="post">
<label class="lbl">Input String</label><br>
32
<input value="<?php echo $txt_shub; ?>" class="inpt" type="text"
name="txt">
<br><br>
<label class="lbl">Reverse String</label><br>
<input value="<?php echo $txt_shub_rev; ?>" class="inpt" type="text"
name="txt_rev">
<br>
<h2><?php echo $msg; ?></h2>
<div class="frm_control">
<a href="index.php">Back</a>
</div>
</form>
</div>
<br>
</body>
</html>
33
Program 14:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Program 1</title>
<style>
.frm{
border:1px solid #000;
padding:20px;
width: 25%;
min-width: 200px;
margin:auto;
background-color: #adadad;
height:400px;
}
.lbl{
font-size:20px;
font-weight: bold;
margin-left:20px;
}
.inpt{
font-size:20px;
color:blue;
margin-left:20px;
margin-top:4px;
padding-left:5px;
}
.frm_control{
margin-top:10px;
}
34
.btn{
width:100px;
height:40px;
background-color: blue;
font-size:20px;
color:cornsilk;
margin-left: 20px;
}
.control{
margin-top:10px;
}
</style>
</head>
<body>
<h1 style="text-align:center;">Program to find the average Marks and
Grade</h1>
<div class="frm">
<article>
<h2 style="text-align:center;backgroundcolor:red;padding:5px;">Average Marks and Grade</h2>
</article>
<form action="result.php" method="post">
<div class="control">
<label class="lbl">Maths</label><br>
<input value=0 class="inpt" type="number" name="m1">
<br>
</div>
<div class="control">
<label class="lbl">Science</label><br>
<input value=0 class="inpt" type="number" name="m2">
<br>
</div>
<div class="control">
<label class="lbl">English</label><br>
<input value=0 class="inpt" type="number" name="m3">
<br>
</div>
<div class="control">
35
<label class="lbl">Computers</label><br>
<input value=0 class="inpt" type="number" name="m4">
<br>
</div>
<div class="frm_control">
<input type="submit" name="submit" class="btn" value="submit">
</div>
</form>
</div>
<br>
</body>
</html>
<?php
$m1_shub = isset($_POST["m1"])?$_POST["m1"]:0;
$m2_shub = isset($_POST["m2"])?$_POST["m2"]:0;
$m3_shub = isset($_POST["m3"])?$_POST["m3"]:0;
$m4_shub = isset($_POST["m4"])?$_POST["m4"]:0;
$sum_shub = $m1_shub+$m2_shub+$m3_shub+$m4_shub;
$avg_shub = $sum_shub/4;
if($avg_shub>70)
{
$grade_shub = "Distinction";
}
elseif($avg_shub>=60 && $avg_shub<70)
{
$grade_shub = "First";
}
elseif($avg_shub>=50 && $avg_shub<60)
{
$grade_shub = "Second";
}
elseif($avg_shub>=40 && $avg_shub<50)
{
$grade_shub = "Third";
}
36
else
{
$grade_shub = "Fail";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Program 1</title>
<style>
.frm{
border:1px solid #000;
padding:20px;
width: 25%;
min-width: 200px;
margin:auto;
background-color: #adadad;
height:450px;
}
.lbl{
font-size:20px;
font-weight: bold;
margin-left:20px;
}
.lblw{
font-size:20px;
font-weight: bold;
margin-left:20px;
color:#f00;
}
.inpt{
font-size:20px;
37
color:blue;
margin-left:20px;
margin-top:4px;
padding-left:5px;
}
.frm_control{
margin-top:10px;
}
.btn{
width:100px;
height:40px;
background-color: blue;
font-size:20px;
color:cornsilk;
margin-left: 20px;
}
</style>
</head>
<body>
<h1 style="text-align:center;">Result Card</h1>
<div class="frm">
<article>
<h2 style="text-align:center;background-color:red;padding:5px;">Score
Card</h2>
</article>
<form action="result.php" method="post">
<h2>Maths: <?php echo $m1_shub;?></h2>
<h2>Science: <?php echo $m2_shub;?></h2>
<h2>English: <?php echo $m3_shub;?></h2>
<h2>Computers: <?php echo $m4_shub;?></h2>
<h2>Total Marks: <?php echo $sum_shub;?></h2>
<h2>Average Marks: <?php echo $m4_shub;?></h2>
<h2>Grade: <?php echo $grade_shub;?></h2>
<div class="frm_control">
<a href="index.php">Back</a>
</div>
</form>
38
</div>
<br>
</body>
</html>
Program 15:
<?php
$a_shub = $_POST["a"];
function sumDigits($n_shub)
{
$n_shubc_shub= $n_shub;
$s_shub=0;
while($n_shub!=0)
{
39
$r_shub = $n_shub%10;
$n_shub=(int)$n_shub/10;
$s_shub =$s_shub+$r_shub;
}
echo "<h1 style='text-align:center;color:#f00;'>Sum of digits of
".$n_shubc_shub." is ". $s_shub."</h1>";
echo "<br><div style='text-align:center;'><a
href='index.php'>BACK</a></div>"; }
sumDigits($a_shub);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Program 1</title>
<style>
.frm{
border:1px solid #000;
padding:20px;
width: 25%;
min-width: 200px;
margin:auto;
background-color: #adadad;
height:250px;
}
.lbl{
font-size:20px;
font-weight: bold;
margin-left:20px;
}
.inpt{
font-size:20px;
color:blue;
margin-left:20px;
margin-top:4px;
40
padding-left:5px;
}
.frm_control{
margin-top:10px;
}
.btn{
width:100px;
height:40px;
background-color: blue;
font-size:20px;
color:cornsilk;
margin-left: 20px;
}
</style>
</head>
<body>
<h1 style="text-align:center;">Program to find sum of digits of a
number</h1>
<div class="frm">
<article>
<h2 style="text-align:center;background-color:red;padding:5px;">sum
of digits of a number</h2>
</article>
<form action="result.php" method="post">
<label class="lbl">Enter value of n</label><br>
<input value=0 class="inpt" type="number" name="a">
<br>
<div class="frm_control">
<input type="submit" name="submit" class="btn" value="submit">
</div>
</form>
</div>
<br>
</body>
</html>
41
Program 16:
<?php
$a_shub = $_POST["a"];
$b_shub = $_POST["b"];
function swap($x_shub,$y_shub)
{
$x_shub = $x_shub+$y_shub;
$y_shub = $x_shub-$y_shub;
$x_shub=$x_shub-$y_shub;
echo "<h1 style='text-align:center;color:#f00;'>After swapping A=
".$x_shub." and B= ".$y_shub."</h1>";
42
echo "<br><div style='text-align:center;'><a
href='index.php'>BACK</a></div>";
}
swap($a_shub,$b_shub);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Program 1</title>
<style>
.frm{
border:1px solid #000;
padding:20px;
width: 25%;
min-width: 200px;
margin:auto;
background-color: #adadad;
height:250px;
}
.lbl{
font-size:20px;
font-weight: bold;
margin-left:20px;
}
43
.inpt{
font-size:20px;
color:blue;
margin-left:10px;
margin-top:4px;
padding-left:5px;
}
.frm_control{
margin-top:10px;
}
.btn{
width:100px;
height:40px;
background-color: blue;
font-size:20px;
color:cornsilk;
margin-left: 20px;
}
</style>
</head>
<body>
<h1 style="text-align:center;">Program to swap two numbers without using
third variable</h1>
<div class="frm">
<article>
<h2 style="text-align:center;backgroundcolor:red;padding:5px;">swapping of numbers</h2>
</article>
44
<form action="result.php" method="post">
<label class="lbl">Enter value of A</label><br>
<input value=0 class="inpt" type="number" name="a">
<br>
<label class="lbl">Enter value of B</label><br>
<input value=0 class="inpt" type="number" name="b">
<br>
<div class="frm_control">
<input type="submit" name="submit" class="btn" value="submit">
</div>
</form>
</div>
<br>
</body>
</html>
45
Download