Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

PHP Programs

Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

Assignment No:1

Assignment Name: Write php script to check integer is even or


odd.

<html>

<head>

</head>

<body>

<form action= evenodd.php method=GET>

Enter the number <br>

<input type=text name=txtadd> <br>

<input type="submit" name="submit">

<?php

if($_GET)

$a=$_GET ['txtadd'];

if($a%2==0)

echo "$a is even";

else

echo "$a is odd";

?>

</form>

</body>

</html>

1
OUTPUT-

2
Assignment No:2
Assignment Name: Accept username and password and nevigate to
homepage with suitable message.
**************************************************************

<html>

<head>

<form action=pass.php method=POST>

Enter Username:<br>

<input type=text name=txt1><br>

Enter Password:<br>

<input type=password name=txt2><br>

<input type=submit name=btn1><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>

<title> Arithmatic Operations</title>

</head>

<body>

<h1 align=center > ARITHMATIC OPERATIONS</H1>

<form action= menu1.php method= POST>

enter two numbers <br>

<input type= text name= txtnum1> <br>

<input type= text name= txtnum2> <br>

enter your choice

<br>

1. addition

<br>

2. substraction

<br>

3. multiplication

<br>

4. division

<br>

<input type= text name= txtnum3> <br>

<input type= submit > <br>

<?php

if ($_POST)

$n1= $_POST ['txtnum1'];

5
$n2= $_POST ['txtnum2'];

$i= $_POST ['txtnum3'];

switch( $i)

case 1:

$i=$n1+$n2;

echo "addition is: $i <br>";

break;

case 2:

$i=$n1-$n2;

echo "sub is: $i <br>";

break;

case 3:

$i=$n1*$n2;

echo "multiplication is: $i <br>";

break;

case 4:

$i= $n1%n2;

echo "division is: $i <br>";

break;

default:

echo "enter valid choice <br>";

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>

<form action= adddigit.php method=POST>

enter the number <br>

<input type=text name=txtadd> <br>

<input type=submit name=submit>

<?php

if($_POST)

$a=$_POST ['txtadd'];

$sum=0;

for($i=$a;$i>0;$i=$i/10)

$rem=$i%10;

$sum=$sum+$rem;

echo "addition of digit=$sum";

?>

</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 action="prime.php" method="post">

<input type="text" name="number"/>

<input type="submit" name="submit"/>

</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)

return "Not Prime";

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 action="palindrome.php" method="post">

<input type="text" name="str" required/>

<input type="submit" name="submit"/>

</form>

</body>

</html>

<?php

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

$n=$_POST['str'];

$rev=strrev($n);

if($n==$rev)

echo "$n is Palindrome";

else

echo "$n is not Palindrome";

?>

19
OUTPUT-

20
**************************************************************
Assignment no: 10
Assignment Name: Write a php script to find leap year or not

**************************************************************

<html>

<body>

<h2>PHP Script to find Leap year or not </h2>

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

<input type="text" name="year" />

<input type="submit" />

</form>

</body>

</html>

<?php

if( $_POST )

$year = $_POST[ 'year' ];

if(!is_numeric($year))

echo "Strings not allowed, Input should be a number";

return;

21
if( (0 == $year % 4) and (0 != $year % 100) or (0 == $year % 400) )

echo "$year is a leap year";

else

echo "$year is not a leap year";

?>

22
OUTPUT-

23
**************************************************************
Assignment no: 11
Assignment Name: Write a PHP script to check if a number is
Armstrong number.

**************************************************************

<html>

<body>

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

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

<input type="submit" name="submit"/>

</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)

echo "Yes it is an Armstrong number";

else

echo "No it is not an armstrong number";

?>

25
OUTPUT-

26
**************************************************************
Assignment no: 12
Assignment Name: Write php program to swap the values of two
numbers using call by reference method.
**************************************************************

<?php

function swap(&$first, &$second)

$temp = $first;

$first = $second;

$second = $temp;

echo "First number ".$first." Second number ".$second."\n";

$a = 5;

$b = 7;

swap ($a, $b);

?>

27
OUTPUT-

28

You might also like