PHP Programs
PHP Programs
PHP Programs
<html>
<head>
</head>
<body>
<?php
if($_GET)
$a=$_GET ['txtadd'];
if($a%2==0)
else
?>
</form>
</body>
</html>
1
OUTPUT-
2
Assignment No:2
Assignment Name: Accept username and password and nevigate to
homepage with suitable message.
**************************************************************
<html>
<head>
Enter Username:<br>
Enter Password:<br>
<?php
if($_POST)
$n1=$_POST['txt1'];
$n2=$_POST['txt2'];
echo $n1."<br>";
echo $n2."<br>";
?>
3
OUTPUT-
4
Assignment No:3
Assignment Name: Write a PHP script to declare two variables
with specific values of your choice and perform arithmetic
operations on them.
**************************************************************
<html>
<head>
</head>
<body>
<br>
1. addition
<br>
2. substraction
<br>
3. multiplication
<br>
4. division
<br>
<?php
if ($_POST)
5
$n2= $_POST ['txtnum2'];
switch( $i)
case 1:
$i=$n1+$n2;
break;
case 2:
$i=$n1-$n2;
break;
case 3:
$i=$n1*$n2;
break;
case 4:
$i= $n1%n2;
break;
default:
break;
?>
</form>
</body>
</html>
6
OUTPUT-
7
**************************************************************
Assignment No:4
Assignment Name: Write a PHP script to declare two variables
with values of your choice and find out greater number between
them.
**************************************************************
<html>
<body>
<form action= greatertwo.php method=POST>
Enter the number <br>
<input type=text name=txtadd1> <br>
<input type=text name=txtadd2> <br>
<input type=submit> <br>
<?php
if($_POST)
{
$a=$_POST['txtadd1'];
$b=$_POST['txtadd2'];
if($a>$b)
{
echo "the greater is a";
}
else
{
echo "the greater is b";
}
}
?>
</form>
</body>
</html>
8
OUTPUT-
9
**************************************************************
Assignment No:5
Assignment Name: Write a PHP script to print.
*****
****
***
**
*
**************************************************************
<?php
for($r=1;$r<=5; $r++)
for($c=5;$c>=$r;$c--)
echo "*";
echo"<br>";
?>
OUTPUT-
10
**************************************************************
Assignment No:6
Assignment Name: Write a PHP script to print sum of digits of
entered number.
**************************************************************
<html>
<body>
<?php
if($_POST)
$a=$_POST ['txtadd'];
$sum=0;
for($i=$a;$i>0;$i=$i/10)
$rem=$i%10;
$sum=$sum+$rem;
?>
</form>
</body>
</html>
11
OUTPUT-
12
**************************************************************
Assignment no: 7
Assignment Name: Write a PHP script to check whether given
variable stores an integer, float, Boolean, null, array,
string.
**************************************************************
<?php
$string = "Yahoo";
//$string = "2500";
//$string = '2500';
$int = 2500;
//$string = "2500.50";
//$string = '2500.50';
$float = 2500.50;
$bool = true;
$bool1 = false;
$null = null;
$array = array("html","css","js","php","java");
echo $string."<br>";
var_dump($string);
echo $int."<br>";
var_dump($int);
echo $float."<br>";
var_dump($float);
echo $bool."<br>";
13
var_dump($bool);
echo $bool1."<br>";
var_dump($bool1);
echo $null."<br>";
var_dump($null);
echo "<br>";
echo $array[1]."<br>";
var_dump($array);
?>
14
OUTPUT-
15
**************************************************************
Assignment no:8
Assignment Name: Write function to check whether a number is
prime or not.
**************************************************************
</form>
<?php
if(isset($_POST['submit']))
echo checkPrime($_POST['number']);
function checkPrime($n)
$flag=0;
for($i=2;$i<$n;$i++)
if($n%$i==0)
$flag=1;
break;
16
if($flag==1)
else
return "Prime";
?>
17
OUTPUT-
18
**************************************************************
Assignment no: 9
Assignment Name: Write a PHP script to check whether a string
is palindrome or not.
**************************************************************
<html>
<body>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
$n=$_POST['str'];
$rev=strrev($n);
if($n==$rev)
else
?>
19
OUTPUT-
20
**************************************************************
Assignment no: 10
Assignment Name: Write a php script to find leap year or not
**************************************************************
<html>
<body>
</form>
</body>
</html>
<?php
if( $_POST )
if(!is_numeric($year))
return;
21
if( (0 == $year % 4) and (0 != $year % 100) or (0 == $year % 400) )
else
?>
22
OUTPUT-
23
**************************************************************
Assignment no: 11
Assignment Name: Write a PHP script to check if a number is
Armstrong number.
**************************************************************
<html>
<body>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
$num=$_POST['number'];
$total=0;
$x=$num;
while($x!=0)
$rem=$x%10;
$total=$total+$rem*$rem*$rem;
$x=$x/10;
24
if($num==$total)
else
?>
25
OUTPUT-
26
**************************************************************
Assignment no: 12
Assignment Name: Write php program to swap the values of two
numbers using call by reference method.
**************************************************************
<?php
$temp = $first;
$first = $second;
$second = $temp;
$a = 5;
$b = 7;
?>
27
OUTPUT-
28