php1
php1
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:
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
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:
PROGRAM:
<!DOCTYPE>
<html>
<body>
<body bgcolor=”blue”text=”white”>
<?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”>
<?php
$i=0;
$num=50;
While($i<10)
$num--;
$i++;
?>
</body>
</html>
RESULT:
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”>
<input type=”submit”name=”submit”value=”addition”/>
</form>
<?php
If(isset($_POST[‘submit’]))
$number1=$_POST[‘number 1’];
$number2=$_POST[‘number 2’];
$num=$number1 + $number2;
}
?>
</body>
</html>
RESULT:
Thus the program was successfully completed.
OUTPUT:
Enter the first number: 23
ADDITION
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”\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>
</head>
<body>
<?php
$numbers=array(21,16,3,8,40,6)
$length=count($numbers);
$max=$number[0];
if($number[$i]>$max)
$max=$numbers[$i];
$min=$numbers[0];
for($i=1;$i<length; $i++)
If($ numbers[$i]<$min;
$min=$number[$i];
?>
</body>
</html>
RESULT:
Thus the program was successfully completed.
OUTPUT:
The biggest number is 40
DATE:
AIM:
To write a Php program for Replacing text with in count.
PROGRAM:
<html>
<head>
<title>COUNT<little>
<? Php
echo str_replace(“facts”,”truth”,$my_str,$count);
echo”<br><br>”;
?>
</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>
</head>
<?php
$my_str=”if the fact does not fit the theory change the fact”;
?>
</html>
RESULT:
Thus the program was successfully completed.
OUTPUT:
Replacing text with in strings
DATE:
AIM:
To write a php program for factorial number.
CODING:
<html>
<head>
</head>
<body>
<?php
$num=10;
$factorial =1;
$factorial=$factorial*$x;
?>
</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>
</head>
<?php
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:
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;
echo “<br>”
?>
</body>
</html>
RESULT:
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
if($num%2==0)
return 1:
else
return 0;
$number=4;
else
print_r(“ “);
echo”<br>”;
$number=3;
if(isEven or Odd($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)
else
?>
RESULT:
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>
<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)
else
?>
RESULT:
Thus the program was successfully completed.
OUTPUT:
Enter the no: 6
Perfect number.