PHP Programs

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 29

1) Armstrong Number using function

HTML

<html>

<head>

<body>

<form action="armstrong.php" method="POST">

<font size="5">

<h1 align="center">Armstrong Number Checking</h1>

Enter a number : <input type="number" name="num"><br>

<input type="submit" value="result">

</font>

</form>

</body>

</head>

</html>

armstrong.php

<html>

<head>

<body>

<font size="5">

<?php

$n=$_POST['num'];

function arm($n)

$d=0;
$sum=0;

$num=$n;

while($n>0)

$d=$n%10;

$sum=$sum+($d*$d*$d);

$n=$n/10;

if($sum==$num)

echo $num." is an Armstrong number <br>";

else

echo $num." is not an Armstrong number <br>";

arm($n)

?>

</font>

</body>

</head>

</html>
2) Identifying Biggest and Smallest Number in an Array

HTML

<html>

<head>

<body>

<form action="arrays.php" method="POST">

<font size="5">

Array Size : <input type="number" name="num"><br>

Array Elts : <input type="text" name="b"><br>

<input type="submit" value="check">

</font>

</form>

</body>

</head>

</html>

arrays.php

<html>

<head>

<body>

<font size=5>

0 <?php

$n=$_POST['num'];

$b=$_POST['b'];

$b=explode(",",$b);

$length=count($b);
$big=$b[0];

$small=$b[0];

$i=1;

if($length==$n)

for($i=0;$i<$n;$i++)

if($b[$i]>$big)

$big=$b[$i];

if($b[$i]<$small)

$small=$b[$i];

for($i=0;$i<$n;$i++)

echo $b[$i]."<br>";

echo "Maximum Element = ".$big."<br>";

echo "Minimum Element = ".$small."<br>";

else

echo "Array size and no. of elements should be same";

?>

</font>

</body>

</head>

</html>
3) Factorial

HTML

<html>

<head>

<link rel="stylesheet" href="mystyle.css">

</head>

<body>

<font color="yellow" size="6">

<form action="find.php" method="POST">

<h1 align=center>Factorial of a number</h1>

<center>

Enter any number : <input type="number" name="num"><br>

<input type="submit" value="Find"><br>

</center>

</form>

</font>

</body>

</html>

mystyle.css

body {

background-image: url("image.jpg");

background-color: #cccccc;

height: 500px;

background-position: center;

background-repeat: no-repeat;
background-size: cover;

position: relative;

find.php

<html>

<body>

<font size=6>

<h1 align=center>Factorial of a number</h1>

<?php

$num=$_POST['num'];

$i=1;

$fact=1;

while($i<=$num)

$fact=$fact*$i;

$i++;

echo "Factorial of ".$num." = ".$fact;

?>

</font>

</body>

</html>
4) Fibonacci Series

HTML

<html>

<body>

<font size=6>

<form action="print.php" method="POST">

<h1 align=center>Printing Fibonacci Series</h1>

Enter the n th value : <input type="number" name="num"><br>

<input type="submit" value="Print">

</form>

</font>

</body>

</html>

print.php

<html>

<body>

<?php

$n=$_POST['num'];

$a=-1;

$b=1;

$i=1;

while($i<=$n)

$c=$a+$b;

$a=$b;
$b=$c;

$i++;

echo $c."<br>";

?>

</body>

</html>

5) Student Mark Table Grade

<html>

<head>

<body>

<form action="student.php" method="POST">

<font size="5">

<h2 align="center">Student Mark Table</h2>

Name : <input type="text" name="na"><br>

Roll No : <input type="text" name="re"><br>

Mark 1 : <input type="number" name="m1"><br>

Mark 2 : <input type="number" name="m2"><br>

Mark 3 : <input type="number" name="m3"><br>

<input type="submit" value="check">

</font>

</form>

</body>

</head>

</html>
student.php

<html>

<head>

<body>

<font size=5>

<?php

$name=$_POST['na'];

$reno=$_POST['re'];

$m1=$_POST['m1'];

$m2=$_POST['m2'];

$m3=$_POST['m3'];

$total=$m1+$m2+$m3;

$ave=$total/3;

echo "Name : ".$name."<br>";

echo "Roll_No : ".$reno."<br>";

echo "Mark 1 : ".$m1."<br>";

echo "Mark 2 : ".$m2."<br>";

echo "Mark 3 : ".$m3."<br>";

if($m1>=40 && $m2>=40 && $m3>=40)

if($ave>=90)

echo "Grade : A+ <br>";

else if($ave>=80)

echo "Grade : A <br>";

else if($ave>=70)
echo "Grade : B+ <br>";

else if($ave>=60)

echo "Grade : B <br>";

else if($ave>=50)

echo "Grade : C <br>";

else if($ave>=40)

echo "Grade : D <br>";

echo "Result : Pass <br>";

else

echo "Grade : Nil <br>";

echo "Result : Fail<br>";

?>

</font>

</body>

</head>

</html>
6) Multiples of 7 and 8 using (include)

HTML

<html>

<head>

<body>

<font size=5 face="arial">

<form action="check.php" method="POST">

Enter No.s = <input type="text" name="a"><br>

<input type="radio" name="m" value="7">Multiples of 7<br>

<input type="radio" name="m" value="8">Multiples of 8<br>

<input type="submit" value="check">

</form>

</font>

</body>

</head>

</html>

check.php

<html>

<head>

<body>

<font face="arial" size="5">

<?php

$arr=$_POST['a'];

$arr=explode(",",$arr);

$ch=$_POST['m'];
echo "Given Values<br>";

foreach($arr as $b)

echo $b."<br>";

if($ch==7)

include '7.php';

else if($ch==8)

include '8.php';

?>

</font>

</body>

</head>

</html>

7.php

<?php

echo "Multiples of 7<br>";

for($i=0;$i<count($arr);$i++)

if($arr[$i]%7==0)

echo $arr[$i]."<br>";

}
8.php

<?php

echo "Multiples of 8<br>";

for($i=0;$i<count($arr);$i++)

if($arr[$i]%8==0)

echo $arr[$i]."<br>";

7) Online Shopping

HTML

<html>

<body>

<style>

body{

background:linear-gradient(to left,skyblue,violet);

h1{

color:darkblue;

font-weigth:900;

font-size:45px;

font-style:italic;

}
table{

border:1px solid black;

p{

font-weight:800;

font-size:20px;

text-align:center;

font-family:consolas;

color:darkblue;

#button{

background-color:skyblue;

padding:10px 20px;

border-radius:12px;

border:1px solid skyblue;

pointer:none;

#button:hover{

background-color:lightgreen;

pointer:none;

</style>

<font>

<h1 align="center">ONLINE MOBILE SHOPPING</h1>


<form action="osc.php" method="POST">

<center>

<table border=1><tr><td>

<br><img src="1.jpg" width=200 height=280>

<p>

<br><br>Iphone 7

<br><br>Amount=Rs.7000<br>

<br>Add to Cart : <input type=checkbox name=b[] value=7000><br><br><br>

</p>

<td>

<br><img src="2.png" width=200 height=280>

<p>

<br><br>Black Berry

<br><br>Amount=Rs.5000<br>

<br>Add to Cart : <input type=checkbox name=b[] value=5000><br><br><br>

</p>

<td>

<br><img src="3.jpg" width=210 height=280>

<p>

<br><br>Any Cool

<br><br>Amount=Rs.10000<br>

<br>Add to Cart : <input type=checkbox name=b[] value=10000><br><br><br>

</p>

<td>

<br><img src="4.gif" width=200 height=280>


<p>

<br><br>Iphone SE

<br><br>Amount=Rs.12000<br>

<br>Add to Cart : <input type=checkbox name=b[] value=12000><br><br><br>

</p>

</td></tr></table><br><br><br><input type="submit" id="button" value="Buy">

</center>

</form>

</body>

</html>

osc.php

<html>

<head>

<body>

<style>

body{

background:linear-gradient(to left,skyblue,violet);

h1{

color:darkblue;

font-weigth:900;

font-size:45px;

font-style:italic;

p{
font-weight:800;

font-size:20px;

text-align:center;

font-family:consolas;

color:darkblue;

</style>

<font>

<h1 align=center>Online Shopping<hr align="center" size="8" width="350"></h1>

<center>

<br>

<?php

$a=$_POST['b'];

$b=0;

$j=0;

echo "<p>";

for($i=0;$i<count($a);$i++)

$j=$j+1;

echo $j;

echo "Item Cost:";

echo "Rs.".$a[$i]."<br>";

$b=$b+$a[$i];

echo "<br>Total Amount:Rs.".$b;


echo "<br><br><br>Items will be delivered with in 10 working days";

echo "</p>";

?>

</body>

</html>

8) No. of times the page viewed (Session)

HTML

<html>

<head>

<body>

<font size=5 face="arial">

<form action="view.php" method="POST">

<input type="submit" value="see">

</form>

</font>

</body>

</head>

</html>

view.php

<html>

<head>

<body>

<font face="arial" size="5">

<?php

session_start();
if(isset($_SESSION['view']))

$_SESSION['view']=$_SESSION['view']+1;

else

$_SESSION['view']=1;

echo "No of times refreshed = ".$_SESSION['view'];

?>

</font>

</body>

</head>

</html>

9) Positive Negative and Zero

HTML

<html>

<body bgcolor="pink">

<font color="red" size="6">

<form action="check.php" method="POST">

<h1 align=center>Check whether the number is positive negative or zero</h1>

<center>

Enter any number : <input type="number" name="num"><br>

<input type="submit" value="check"></center >

</form>
</font>

</body>

</html>

check.php

<html>

<body>

<?php

$num=$_POST['num'];

if($num>0)

echo "It is a positive number";

else if($num<0)

echo "It is a negative number";

else

echo "The Number is zero";

?>

</body>

</html>

10) Reversing the number

HTML

<html>

<head>

<body>

<form action="reverse.php" method="POST">

<font size="5">

<h1 align="center">Reversing a number</h1>


Enter a number : <input type="number" name="num"><br>

<input type="submit" value="result">

</font>

</form>

</body>

</head>

</html>

reverse.php

<html>

<head>

<body>

<font size="5">

<?php

$n=$_POST['num'];

function rever($n)

$d=0;

$ans=0;

while($n>1)

$d=$n%10;

$ans=($ans*10)+$d;

$n=$n/10;

return $ans;
}

echo "Reverse of ".$n." = ".rever($n)."<br>";

?>

</font>

</body>

</head>

</html>

11) Simple Interest and Compound Interest

HTML

<html>

<body bgcolor="pink">

<h1>Simple and Compound Interest</h1>

<form action="si.php" method="POST">

Principal amount:<input type="number" name="p"><br>

No. Of years :<input type="number" name="n"><br>

Rate of Interest :<input type="number" name="r"><br>

<input type="submit" value="click">

</form>

</body>

</html>

si.php

<html>

<body>

<h1>

<?php
$p=$_POST['p'];

$n=$_POST['n'];

$r=$_POST['r'];

$si=$p*$n*$r/100;

echo "simple interest=".$si."<br>";

$amount=$p*pow((1+$r/100),$n);

$ci=$amount-$p;

echo "compound interest=".$ci;

?>

</h1>

</body>

</html>

12) String Operations

HTML

<html>

<head>

<body>

<form action="string.php" method="POST">

<font size="5">

<h2 align="center">String Operations</h2>

<input type="radio" name="ch" value="1">String Comparison<br>

Enter String 1 : <input type="text" name="s1">

Enter String 2 : <input type="text" name="s2"><br>

<input type="radio" name="ch" value="2">Reversing the String<br>

Enter a String : <input type="text" name="s3"><br>


<input type="radio" name="ch" value="3">String Length<br>

Enter a String : <input type="text" name="s4"><br>

<input type="radio" name="ch" value="4">No. of words in a String<br>

Enter a String : <input type="text" name="s5"><br>

<input type="radio" name="ch" value="5">All words 1st letter is capital<br>

Enter a String : <input type="text" name="s6"><br>

<input type="submit" value="Result">

</font>

</form>

</body>

</head>

</html>

string.php

<html>

<head>

<body bgcolor="cyan">

<font size=5>

<?php

$ch=$_POST['ch'];

$s1=$_POST['s1'];

$s2=$_POST['s2'];

$s3=$_POST['s3'];

$s4=$_POST['s4'];

$s5=$_POST['s5'];

$s6=$_POST['s6'];
switch($ch)

case 1:

if(strcmp($s1,$s2)==0)

echo $s1." and ".$s2. " are same";

else

echo $s1." and ".$s2. " are different";

break;

case 2:

echo "Reverse of ".$s3." = ".strrev($s3)."<br>";

break;

case 3:

echo "Length of ".$s4." = ".strlen($s4)."<br>";

break;

case 4:

echo "No. of words in ...".$s5." = ".str_word_count($s5)."<br>";

break;

case 5:

echo "Before using ucwords function : ".$s6."<br>";

echo "After using ucwords function : ".ucwords($s6)."<br>";

break;

?>

</font>

</body>
</head> </html>

13) Sum of Digits using functions

HTML

<html>

<head>

<body>

<form action="sum.php" method="POST">

<font size="5">

<h1 align="center">Sum Of Digits</h1>

Enter a number : <input type="number" name="num"><br>

<input type="submit" value="result">

</font>

</form>

</body>

</head>

</html>

sum.php

<html>

<head>

<body>

<font size="5">

<?php

$n=$_POST['num'];

$d=0;
function sum_of_digits($n)

$ans=0;

while($n>0)

$d=$n%10;

$ans=$ans+$d;

$n=$n/10;

return $ans;

echo "Sum of Digits of ".$n." = ".sum_of_digits($n)."<br>";

?>

</font>

</body>

</head>

</html>

14) Volume of sphere and volume of cylinder

HTML

<html>

<body bgcolor="tomato">

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

<p>volume cylinder</p>

enter the height:<input type="text" name="h"><br>

enter the radius:<input type="text" name="r"><br>


<p>volume of sphere</p>

enter the radius:<input type="text" name="r1"><br>

<input type="submit" value="click">

</form>

</body>

</html>

volume.php

<html>

<body>

<h1>

<?php

$r=$_POST['r'];

$h=$_POST['h'];

$cy=$r*$r*$h;

echo "volume of cylinder= ".$cy;

$r1=$_POST['r1'];

$sp=4/3*(3.14)*$r1*$r1*$r1;

echo "volume of sphere= ".$sp;

?>

</h1>

</body>

</html>
15) Voter Eligiblity

HTML

<html>

<body bgcolor="tomato">

<form action="vote.php" method="POST">

Enter the Age:<input type=number name="age">

<input type="submit" value="click">

</form>

</body>

</html>

vote.php

<html>

<body>

<?php

$s=$_POST['age'];

if($s>=18)

echo "your eligible to vote";

else

echo "your not eligible to vote";

?>

</body>

</html>

You might also like