Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
6 views

php1

This document outlines the PHP lab practicals for the 2 BSC(CS) class at N.M.S. Sermathai Vasan College for Women. It includes a bonafide certificate, an index of exercises, and detailed PHP programs for various tasks such as sorting numbers, calculating sums, and identifying prime and Armstrong numbers. Each program is accompanied by its aim, code, result, and output.

Uploaded by

sundar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

php1

This document outlines the PHP lab practicals for the 2 BSC(CS) class at N.M.S. Sermathai Vasan College for Women. It includes a bonafide certificate, an index of exercises, and detailed PHP programs for various tasks such as sorting numbers, calculating sums, and identifying prime and Armstrong numbers. Each program is accompanied by its aim, code, result, and output.

Uploaded by

sundar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

N.M.S.

SERMATHAI VASAN COLLEGE FOR WOMEN


(ACCREDITED WITH “B” GRADE BY NAAC)
AVANIYAPURAM
MADURAI-12

DEPARTMENT OF CS,IT,BCA AND DS

CLASS : 2BSC(CS)
SUBJECT : PHP LAB
SUBJECT CODE :
YEAR : JAN 2024 –MAY 2024
N.M.S SERMATHAI VASAN COLLEGE FOR WOMEN
(ACCREDITED WITH “B” GRADE BY NAAC )
MADURAI-12

BONAFIDE CERTIFICATE
REG NO: CLASS: 2 BSC(CS)
SUBJECT:PHP LAB SUBJECT CODE:

This certified to be the Bonafide Record Work Done by


__________________ submitted for the practical examination held at
N.M.S.SERMATHAI VASAN COLLEGE FOR WOMEN,
MADURAI-12 Dated on ____________________

HOD signature STAFF INCHARGE

INTERNAL EXAMINER EXTERNALEXAMINER


INDEX`
S.NO DATE TITLE Page STAFF’S
no SIGN
1. ASCENDING ORDER

2. DESCENDING ORDER

3. SUM OF DIGIT

4. LOOPING CONDITION

5. ARRAY

6. STAR

7. ADDITION

8. MULTIPLICATION TABLE

9. FIBONACCI SERIES

10. BIGGEST&SMALLEST
NUMBER
11. REPLACING TEXT WITH IN
COUNT
12. REPLACING TEXT WITH IN
STRINGS
13. FACTORIAL NUMBER
14. CALCULATING THE
LENGTH OF THE STRING
15. NULL SET
16. PRINT THE PRODUCT
17. ODD OR EVEN

18. PRIME NUMBER

19. ARMSTRONG NUMBER

20. PERFECT NUMBER


ASCENDING ORDER
EX:NO:1

DATE:

AIM:
To write a php program for Ascending order.

PROGRAM:
<!DOCTYPE html>

<html>

<body>

<body bgcolor=”yellow”text=”black”>

<?php

$numbers=array(4,16,17,18,19);

Sort($numbers);

$arrlength=count($numbers);

for($x=0;$x<$arrlength;$x++)

echo $numbers[$x];

echo”<br>”;

?>

</body>

</html>

RESULT:
Thus the program was successfully completed.
OUTPUT:
4

16

17

18

19
DESCENDING ORDER
EX:NO:2

DATE:

AIM:
To write a php program for Descending order.

PROGRAM:
<!DOCTYPE html>

<html>

<body>

<body bgcolor=”yellow”text=”black”>

<?php

$numbers=array(4,16,17,18,19);

rsort($numbers);

$arrlength=count($numbers);

for($x=0;$x<$arrlength;$x++)

echo $numbers[$x];

echo”<br>”;

?>

</body>

</html>

RESULT:
Thus the program was successfully completed.
OUTPUT:
19
18
17
16
4
SUM OF DIGITS
EX:NO:3

DATE:

AIM:

To write a php program for Sum of digits.

PROGRAM:
<!DOCTYPE>

<html>

<body>

<body bgcolor=”blue”text=”white”>

<h1> sum of digits</h1>

<?php

$n=127;

$sum=0;

$rem=0;

While($n>0)

$rem=$n%10;

$sum=$sum+$rem;

$n=$n/10;

echo”sum = $sum”;

?>

</body>

</html>
RESULT:
Thus the program was successfully completed.

OUTPUT:
Sum of digits

Sum=10.
LOOPING CONDITION
EX:NO:4

DATE:

AIM:
To write a php program for looping condition.

PROGRAM:
<!DOCTYPE>

<html>

<body>

<body bgcolor=”pink”text=”black”>

<h1> looping condition</h1>

<?php

$i=0;

$num=50;

While($i<10)

$num--;

$i++;

echo(“loop stopped at i=$i and num=$num”);

?>

</body>

</html>

RESULT:

Thus the program was successfully completed.


OUTPUT:
LOOPING CONDITION

Loop stopped at i=10 and num=40.


ARRAY
EX:NO:5

DATE:

AIM:
To write a php program for array.

PROGRAM:
<!DOCTYPE html>

<html>

<body>

<body bgcolor=”purple”text=”black”>

<?php

$numbers=array(40,41,22,2,13);

sort($numbers);

$arrlength=count($number);

for($x=0;$x<$arrlength;$x++)

echo $numbers[$x];

echo”<br>”;

?>

</body>

</html>

RESULT:
Thus the program was successfully completed.
OUTPUT:
2
13
22
40
41
STAR
EX:NO:6

DATE:

AIM:
To write a php program for star.

PROGRAM:
<!DOCTYPE html>

<html>

<body>

<body bgcolor=”white”text=”black”>

<h1>STAR</h1>

<?php

for($i=1;$i<=5;$i++)

for($j=1;$j<=$i;$j++)

echo’*’;

echo’<br>’;

for($i=5;$i>=1;$i--)

for($j=1;$j<=$i;$j++)

{
echo’*’;

echo’<br>’;

?>

</body>

</html>

RESULT:
Thus the program was successfully completed.

OUTPUT:
*

**

***

****

*****

*****

****

***

**

*
ADDITION
EX:NO:7

DATE:

AIM:
To write a php program for Addition.

PROGRAM:
<!DOCTYPE html>

<html>

<body>

<form method=”POST”>

Enter the first number

<input type=”number”name=”number 1”/><br><br>

Enter the second number

<input type=”number”name=”number 2”/><br><br>

<input type=”submit”name=”submit”value=”addition”/>

</form>

<?php

If(isset($_POST[‘submit’]))

$number1=$_POST[‘number 1’];

$number2=$_POST[‘number 2’];

$num=$number1 + $number2;

Echo”the difference of $number 1 and $number2 is:”,$num;

}
?>

</body>

</html>

RESULT:
Thus the program was successfully completed.

OUTPUT:
Enter the first number: 23

Enter the second number: 24

ADDITION

The difference of 23 and 24 is 47.


MULTIPLICATION TABLE
EX:NO:8
DATE:
AIM:
To write a php program for multiplication table.

PROGRAM:
<!DOCTYPE html>

<head>

<title>star</title>

</head>

<body bgcolor=”pink”>

<?php

$i=2;

For($table_counter=1;$table_counter<=10;$table_counter++)

Printf(“%d*%d=%d”,$i,$table_counter,($i*$table_counter));

echo”<br>”;

echo””;

?>

</body>

</html>
RESULT:
Thus the program was successfully completed.

OUTPUT:
2*1=2

2*2=4

2*3=6

2*4=8

2*5=10

2*6=12

2*7=14

2*8=16

2*9=18

2*10=20
FIBONACCI SERIES
EX:NO:9

DATE:

AIM:
To write a php program for fibonacci series.

PROGRAM:
<html>

<head>

<body>

<?php

$num=0;

$n1=0;

$n2=1

echo “<n3>Fibonacci series for first 12 number:</n3>;

Echo”\n”;

While<$num<10)

$n3=$n2+$n1;

echo$n3;

echo”<br>”;

$ n1=$ n2;

$n2=$ n3;

$num = $num+1;

}
?>

</body>

</head>

</html>

RESULT:
Thus the program was successfully completed.

OUTPUT:
Fibonacci series for first 12 numbers

13

21

34

55

89.
BIGGEST & SMALLEST NUMBER
EX:NO:10

DATE:

AIM:
To write a php program for biggest &smallest number.

PROGRAM:
<!DOCTYPE html>

<html>

<head>

<title> BIG & SMALL NUMBER</title>

</head>

<body>

<?php

$numbers=array(21,16,3,8,40,6)

$length=count($numbers);

$max=$number[0];

for($i=1; $i<$length; $i++)

if($number[$i]>$max)

$max=$numbers[$i];

echo” The biggest number is”,$max;


echo” <br>”;

$min=$numbers[0];

for($i=1;$i<length; $i++)

If($ numbers[$i]<$min;

$min=$number[$i];

echo” The smallest number is “,$min;

?>

</body>

</html>

RESULT:
Thus the program was successfully completed.

OUTPUT:
The biggest number is 40

The smallest number is 3.


REPLACING TEXT WITH IN COUNT
EX: NO: 11

DATE:

AIM:
To write a Php program for Replacing text with in count.

PROGRAM:
<html>

<head>

<title>COUNT<little>

<? Php

$my_str=”If the facts do not fit theory ,change the facts”;

echo str_replace(“facts”,”truth”,$my_str,$count);

echo”<br><br>”;

echo ”The text was replaced $count times”;

?>

</body>

</html>

RESULT:
Thus the program was successfully completed.

OUTPUT:
The text was replace 2 times.
REPLACING TEXT WITH STRING
EX:NO: 12

DATE:

AIM:
Write a php program for Replace Text with in string.

PROGRAM:
< html>

<head>

<title>replacing text with in string </title>

</head>

<?php

$my_str=”if the fact does not fit the theory change the fact”;

echo str_replace(“fact”,”truth”,$my str);

?>

</html>

RESULT:
Thus the program was successfully completed.

OUTPUT:
Replacing text with in strings

If the truth does not fit the theory,change the truth.


FACTORIAL NUMBER
EX:NO:13

DATE:

AIM:
To write a php program for factorial number.

CODING:
<html>

<head>

<title>factorial program using loop in php</title>

</head>

<body>

<h1> factorial </h1>

<?php

$num=10;

$factorial =1;

For ($x=$num; $x>1;$x--)

$factorial=$factorial*$x;

Echo “factorial of $num is $ factorial”;

?>

</body>

</html>
RESULT:
Thus the program was successfully completed.

OUTPUT:
FACTORIAL

Factorial of 10 is 3628800.
CALCULATING LENGTH OF STRING
EX:NO:14

DATE:

AIM:
To write a php program for calculating length of string.

PROGRAM:
<html>

<body>

<head>

<title> Calculate length of the string</title>

</head>

<?php

$my_str= “welcome to tutorial class”;

echo “$my_str”;

echo”<br>”;

?>

</body>

</html>

RESULT:
Thus the program was successfully completed.

OUTPUT:
Calculating length of string :28
NULL SET
EX:NO:15

DATE:

AIM:
To write a php program was Null set.

PROGRAM:
<!DOCTYPE html>

<html>

<body>

$x =”hello world”)

$x =null;

Var_dumps($x);

?>

</body>

</html>

RESULT:

Thus the program was successfully completed.

OUTPUT:

NULL.
PRINT THE PRODUCT
EX:NO:16
DATE:

AIM:
To write a php program was print the product.

PROGRAM:
<!DOCTYPE html>

<html>

<body>
<? Php

$num =9;

For($i=1; $i<=10; $i++)

$ product =$i* $num;

echo “$num”$i= $product”;

echo “<br>”

?>

</body>

</html>

RESULT:

Thus the program was successfully completed.


OUTPUT:
9*1=9

9*2=18

9*3=27

9*4=36

9*5=45

9*6=54

9*7=63

9*8=72

9*9=81

9*10=90
ODD OR EVEN
EX:NO:17

DATE:

AIM:
To write a php program for ODD OR EVEN.

PROGRAM:
<html>

<body>

<? Php

function is Ever or Odd($num)

if($num%2==0)

return 1:

else

return 0;

$number=4;

if(is Even or Odd($number))

print_r($number, ”is even num”);

else

print_r($number. ”is odd num”);

print_r(“ “);

echo”<br>”;
$number=3;

if(isEven or Odd($number)

print_r($number.”is Even number”);

else

print_r($number.”Odd num”);

?>

</body>

</html>

Result:
Thus the program was successfully completed.

OUTPUT:

4 is even number.

3 is odd number.
PRIME NUMBER
EX:NO:18

DATE:

AIM:
Write a program in php program for prime number.

CODING:

<? Php

$count=0;

$num=2;

While ($count<15)

$div_count=0;

For($i=1;$i<=$num;$i++)

{
if(($num%$i)==0)

$div_count++;

}}

If($div_count<3)

echo $num.”,”;

$count=$count+1;

$num=$num+1;
}

?>

RESULT:
Thus the program was successfully completed.

OUTPUT:
2,3,5,7,11,13,17,19,23,29,31,37,41,43,47.
ARMSTRONG NUMBER
EX:NO:19

DATE:

AIM:
Write a program in php program for Armstrong number .

CODING:
<? Php

$num=407;

$total=0;

$x=$num;

While($x%10)

$rem=$x%10;

$total=$total+$rem*$rem*$rem;

$x=$x/10;

If($num==$total)

echo ”yes it is an Armstrong number”;

else

echo ”No it is not an Armstrong number”;

?>
RESULT:

Thus the program was successfully completed.

OUTPUT:
Yes it is an Armstrong number.
PERFECT NUMBER
EX:NO 20

DATE:

AIM:
Write a program in php program for perfect number.

PROGRAM:
<html>

<body>

<h2> perfect number<\h2>

<form action=” “method=”post”>

Enter the number:

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

<input type=”submit”/>

</form>

</body>

</html>

<?php

if($_post){

$no=$-POST[“number”];

$sum=0;

for($i=1;$i<$no;$i++)

if($no%$i=0)

$sum=$sum+$i;
}

if($sum==$no)

echo “perfect number”;

else

echo”not a perfect number”;

?>

RESULT:
Thus the program was successfully completed.

OUTPUT:
Enter the no: 6

Perfect number.

You might also like