0% found this document useful (0 votes)
46 views22 pages

PHP File

PHP programming file. Lot of program are written on their.

Uploaded by

Arzoo raza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views22 pages

PHP File

PHP programming file. Lot of program are written on their.

Uploaded by

Arzoo raza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

DAV institute of Engineering & Technology

(Jalandhar)

Bachelor of computer Applications


Practical file
(Programming in PHP)

Submitted to:- Submitted by :- Vivek Raj


Gurnirdesh Singh Class:- BCA 5th sem
Uni. Roll no :- 2202140
Class Roll no:- 3288/22
INDEX
S.NO. PRACTICAL NAME PAGE NO. REMARKS

1 Take values from the user and


compute sum, subtraction,
multiplication, division, and exponent
of value of the variables.

2 Write a program to find area of


following shapes: circle, rectangle,
triangle, square, trapezoid and
parallelogram.
3 Compute and print roots of quadratic
equation.
4 Write a program to determine
whether a triangle is isosceles
or not?

5 Print multiplication table of a


number input by the user
6 Calculate sum of natural numbers
from one to n number.

7 Print Fibonacci series up to n


numbers e.g. 0 1 1 2 3 5 8 13
21….n
8 Write a program to find the
factorial of any number.

2
9 Determine prime numbers within
a specific range.

10 Write a program to compute, the


Average and Grade of students’
marks.
11 Compute addition, subtraction and
multiplication of a matrix.

12 Count total number of vowels in a


word “Develop & Empower
Individuals”
13 Determine whether a string is
palindrome or not?

14 Display word after Sorting in


alphabetical order.
15 Check whether a number is in a
given range using functions.

16 Write a program accepts a string and


calculates number of upper-case
letters and lower-case letters
available in that string.
17 Design a program to reverse a
string word by word.

18 Write a program to create a login


form. On submitting the form, the user
should navigate to profile page.
19 Design front page of a college
or department using graphics
method.
20 Write a program to upload
and download files.
1. Take values from the user and compute sum, subtraction,
multiplication,division and exponent of value of the
variables.
<?php
$a = readline('Enter a num = ');
$b = readline('Enter a num = ');
echo("addition of two num = ");
echo $a+$b ."\n";
echo("substraction of two num = ");
echo $a-$b ."\n";
echo("multiplication of two num = ");
echo $a*$b ."\n";
echo("division of two num = ");
echo $a/$b ."\n";
echo("exponent of two num = ");
echo (pow($a,$b)) ."\n";
?>
2. Write a program to find area of following shapes: circle, rectangle,
triangle, square, trapezoid and parallelogram
<?php
echo "Area of Circle "."\n";
$pi = 3.14;
$radius = (int)readline("Enter the value of Radius = ");
$area = $pi*$radius*$radius;
echo "The area of circle is = ".$area;
echo "\n";
echo "Area of rectangle"."\n";
$length = (int)readline("Enter the value of Length = ");
$breadth = (int)readline("Enter the value of Breadth = ");
$area1 = $length*$breadth;
echo "The area of Rectangle is = ".$area1;
echo "\n";
echo "Area of Triangle "."\n";
$base = (int)readline("Enter the value of Base = ");
$height = (int)readline("Enter the value of height = ");
$area2 = ($base*$height)/2;
echo "The area of Triangle is ".$area2;
echo "\n";
echo "Area of Square"."\n";
$side = (int)readline("Enter the value of Side = ");
$area3 =$side*$side;
echo "The area of Square is = ".$area3;
echo "\n";
?>
3. Compute and print roots of quadratic equation.
<?php
echo "The program of Quadrtic equation ";
$a = (int)readline("Enter the Value of A = ");
$b = (int)readline("Enter the Value of B = ");
$c = (int)readline("Enter the Value of C = ");

$d = ($b*$b)-4*$a*$c;
if($d>0){
$q1 = (-$b+sqrt($d))/2*$a;
$q2 = (-$b-sqrt($d))/2*$a;
echo "The value of equation q1 and q2 is".($q1).($q2);
}
else if($d==0){
$q3 = -$b/2*$a;
echo "The value of q3 is ".$q3;
}
else{
echo "Root are imagenary!";
}
?>
4. Write a program to determine whether a triangle is isosceles or not?
<?php
$side1 = readline('Enter the value of side1 = ');
$side2 = readline('Enter the value of side2 = ');
$side3 = readline('Enter the value of side3 = ');
if($side1 == $side2 && $side2 == $side3){
echo("The Given Triangle is equilateral");
}
elseif($side1 == $side2 || $side2 == $side3 || $side3 == $side1){
echo("The given Triangle is isosceles");
}
else{
echo("The given Triangle is scaleecho");
}
?>

5. Print multiplication table of a number input by the user.


<?php
$a = readline('Enter a num = ');
for($i=1; $i<=10; $i++){
echo $a*$i ."\n";
}
?>
6. Calculate sum of natural numbers from one to n number
<?php
$n = 10;
$i = 1;
$sum = 0;
while($i <= $n) {
$sum += $i;
$i++;
}
echo "Sum is: $sum";
?>

7. print Fibonacci series up to n numbers e.g. 0 1 1 2 3 5 8 13 21…..n


<?php
$n = 0;
$a = 0;
$b = 1;
echo "Fibonacci series with the first 8 numbers: "; echo "$a, $b";
while ($n < 8){
$c = $b + $a; echo ", ";
echo $c;
$a = $b;
$b = $c;
$n = $n + 1;
}
?>

8. Write a program to find the factorial of any number.


<?php
$n = 4;
$f = 1;
for ($i=$n; $i>=1; $i--){
$f = $f * $i;
}
echo "$n! = $f";
?>
9. Determine prime numbers within a specific range.
<?php
$count = 0;
$num = 1;
while ($count < 10 ){
$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;
}
?>
10. Write a program to compute, the Average and Grade of students
marks
<?php
$sub_1 = 95;
$sub_2 = 85;
$sub_3 = 74;
$sub_4 = 64;
$sub_5 = 53;
$total = NULL;
$average = NULL;
$percentage = NULL;
$grade = NULL;
$total = $sub_1 + $sub_2 + $sub_3 + $sub_4 + $sub_5;
$average = $total / 5.0;
$percentage = ($total / 500.0) * 100;

if ($average >= 90){


$grade = "A";
}

else if ($average >= 80 && $average < 90){


$grade = "B";
}

else if ($average >= 70 && $average < 80){


$grade = "C";
}
else if ($average >= 60 && $average < 70){
$grade = "D";
}
else{
$grade = "E";
}
echo "The Total marks = " . $total . "/500\n"; echo "The Average marks = " . $average .
"\n"; echo "The Percentage = " . $percentage . "%\n"; echo "The Grade = '" . $grade .
"'\n";
?>
11. Compute addition, subtraction and multiplication of a matrix.
Addition
<?php
$a1 = array( array(4, 6, 7),
array(3, 9, 9),
array(5, 4, 8)
);
$a2 = array( array(6, 7, 5),
array(9, 2, 1),
array(6, 8, 3)
);
$row = count($a1);
$col = count($a1[0]); echo "First matrix: \n";
for ($i = 0; $i < $row; $i++) {
for ($j = 0; $j < $col; $j++) {
echo $a1[$i][$j] . " ";
}
echo "\n";
}
echo "Second matrix: \n";
for ($i = 0; $i < $row; $i++) {
for ($j = 0; $j < $col; $j++){
echo $a2[$i][$j] . " ";
}
echo "\n";
}
$sum = array();
for ($i = 0; $i < $row; $i++) {
for ($j = 0; $j < $col; $j++) {
$sum[$i][$j] = $a1[$i][$j] + $a2[$i][$j];
}
}
echo "Addition of two matrices: \n";
for ($i = 0; $i < $row; $i++) {
for ($j = 0; $j < $col; $j++) {
echo $sum[$i][$j] . " ";
}
echo "\n";
}
?>
Subtraction
<?php
$arr1 = array( array(6, 7, 7),
array(9, 5, 2),
array(8, 4, 8)
);
$arr2 = array( array(4, 6, 5),
array(3, 2, 1),
array(6, 3, 3)
);
$row = count($arr1);
$col = count($arr1[0]);
echo "First matrix: \n";
for ($i = 0; $i < $row; $i++) {
for ($j = 0; $j < $col; $j++) {
echo $arr1[$i][$j] . " ";
}
echo "\n";
}
echo "Second matrix: \n";
for ($i = 0; $i < $row; $i++) {
for ($j = 0; $j < $col; $j++) {
echo $arr2[$i][$j] . " ";

}
echo "\n";
}
$sub_arr = array();
for ($i = 0; $i < $row; $i++) {
for ($j = 0; $j < $col; $j++) {
$sub_arr[$i][$j] = $arr1[$i][$j] - $arr2[$i][$j];
}
}
echo "Subtraction of two matrices: \n";
for ($i = 0; $i < $row; $i++) {
for ($j = 0; $j < $col; $j++) {
echo $sub_arr[$i][$j] . " ";
}
echo "\n";
}
?>

12. Count total number of vowels in a word “Develop & Empower


Individuals”.
<?php
{
$string="Abhi is nice man!";
$vowels = array('a','e','i','o','u');
$len = strlen($string);
$num = 0;

for($i=0; $i<$len; $i++){


if(in_array($string[$i], $vowels)){
$num++;
}
}
echo "$num";
function countDigits( $string ){
return preg_match_all( "/[0-9]/", $string );
}
substr_count($string, ' ');
echo "Number of vowels :". $num;}
?>

13. Determine whether a string is palindrome or not?


<?php
$input = readline("Enter the String = ");
$reverse = strrev($input);
if($input == $reverse) {
echo $input.' is a palindrome' ;
}
else {
echo $input.' is not a palindrome';
}
?>

14. Display word after Sorting in alphabetical order.


<?php
$text = array("Rahul", "Abhishek", "Sandhya", "Anjali", "Raman");
$numbers = array(2, 3, 4.5, 6, 9,15);
sort($text);
print_r($text);
echo "\n";
sort($numbers);
print_r($numbers);
?>
15. Check whether a number is in a given range using functions.
<?php
$arr = range(0,100,20);
foreach ($arr as $a) {
echo "$a ";
}
?>

16. Write a program accepts a string and calculates number of upper case
letters and lower case letters available in that string .
 UPPERCASE
<?php
$str_upper = "I am good boy";
echo strtoupper($str_upper);
?>

 LOWERCASE
<?php
$str_mixed = "i LOVE YOU BUT i can'T LIVE WITH YOU";
echo strtolower($str_mixed);
?>

17. Design a program to reverse a string word by word.


<?php
$string = "HUM KHUSH HUE";
echo "Reverse string of $string is = " .strrev ($string );
?>
18. Write a program to create a login form. On submitting the form, the
user should navigate to profile page.
<!DOCTYPE HTML>
<html>
<body>
<form action="new.php" method="post">
Name: <input type="text" name="name"><br><br>
E-mail: <input type="text" name="email"><br><br>
<input type="submit">
</form>
</body>
</html

PHP File name:- new.php

<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>

19. Design front page of a college or department using graphics method.


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>College of Computer Science</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<!-- Header Section -->
<header>
<div class="logo">
<img src="logo.png" alt="College Logo">
</div>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Courses</a></li>
<li><a href="#">Admissions</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</header>
<!-- Hero Section -->
<section class="hero">
<div class="hero-text">
<h1>Welcome to the College of Computer Science</h1>
<p>Your gateway to innovative technology and learning.</p>
<a href="#about" class="btn">Learn More</a>
</div>
</section>
<!-- About Section -->
<section id="about" class="about">
<h2>About Us</h2>
<p>We are a leading department focused on the development of
cutting-edge computer science education, research, and innovation. Our
mission is to prepare students for careers in technology and solve complex
problems through innovative solutions.</p>
</section>
<!-- Courses Section -->
<section class="courses">
<h2>Programs and Courses</h2>
<div class="course-list">
<div class="course">
<h3>Bachelor of Computer Science</h3>
<p>An undergraduate program focused on software
development and computing fundamentals.</p>
</div>
<div class="course">
<h3>Master of Computer Science</h3>
<p>A graduate program offering advanced courses in artificial
intelligence, data science, and machine learning.</p>
</div>
<div class="course">
<h3>PhD in Computer Science</h3>
<p>A research-oriented program with a focus on emerging areas
of computing and technology.</p>
</div>
</div>
</section>

<!-- Footer Section -->


<footer>
<p>Contact us at <a
href="mailto:[email protected]">[email protected]</a></p>
<p>Follow us:
<a href="#">Facebook</a> |
<a href="#">Twitter</a> |
<a href="#">LinkedIn</a>
</p>
<p>&copy; 2024 College of Computer Science</p>
</footer>
</body>
</html>

/* General Styles */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
box-sizing: border-box;
}

a{
text-decoration: none;
color: inherit;
}

/* Header Section */
header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px;
background-color: #333;
color: white;
}

header .logo img {


width: 100px;
}
header nav ul {
display: flex;
list-style-type: none;
gap: 20px;
}

header nav ul li a {
color: white;
font-size: 18px;
}

header nav ul li a:hover {


color: #ff6347;
}

/* Hero Section */
.hero {
background: url('hero-image.jpg') no-repeat center center/cover;
color: white;
text-align: center;
padding: 100px 20px;
}
.hero h1 {
font-size: 3em;
margin-bottom: 10px;
}
.hero p {
font-size: 1.5em;
margin-bottom: 20px;
}
.hero .btn {
background-color: #ff6347;
padding: 15px 30px;
font-size: 1.2em;
color: white;
border: none;
border-radius: 5px;
}
.hero .btn:hover {
background-color: #ff4500;
}
/* About Section */
.about {
padding: 50px 20px;
background-color: #f4f4f4;
text-align: center;
}
.about h2 {
font-size: 2.5em;
margin-bottom: 20px;
}
.about p {
font-size: 1.2em;
line-height: 1.6;
max-width: 800px;
margin: 0 auto;
}
/* Courses Section */
.courses {
padding: 50px 20px;
background-color: white;
text-align: center;
}
.courses h2 {
font-size: 2.5em;
margin-bottom: 20px;
}
.course-list {
display: flex;
justify-content: space-around;
gap: 20px;
flex-wrap: wrap;
}
.course {
background-color: #ff6347;
color: white;
padding: 20px;
width: 300px;
border-radius: 10px;
text-align: center;
}
.course h3 {
font-size: 1.8em;
margin-bottom: 10px;
}
.course p {
font-size: 1.2em;
}
/* Footer Section */
footer {
padding: 20px;
background-color: #333;
color: white;
text-align: center;
}
footer a {
color: #ff6347;
}
footer a:hover {
color: white;
}
Output
20. Write a program to upload and download files.
<!DOCTYPE html>
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>

You might also like