Server-Side Scripting (PHP)
SOP 1: Write a PHP program to check if a person
is eligible to vote or not. The program
should include the following.
·
Minimum
age required for vote is 18.
·
Use
Php functions.
·
Use
Decision making statement.
age.html
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1 align="center"> Person
Eligible to vote or not</h1>
<form method="post"
action="age.php">
Enter Your age
<input type="text"
name="age"> <br> <br>
<input type="submit"
name="submit" value="Check Eligible">
</form>
</body> </html>
Age.php
<?php
if(isset($_POST['submit']))
{
$age=$_POST['age'];
if($age>=18)
echo"<br> <br> You are Eligible
to vote";
else
echo"<br><br> You are not
Eligible to vote";
}
?>
SOP 2: Write a PHP function to count the total number
of vowels (a,e,i,o,u) from the string. Accept a string by using HTML form.
Vowel.html
<!DOCTYPE html>
<html>
<head>
<title></title> </head>
<body>
<h1 align="center">String
Function</h1>
<form action="vowel.php"
method="post">
Enter String :<input type="text"
name="str"> <br>
<input type="submit"
name="submit" value="Count Vowels">
</form> </body>
</html>
Vowel.php
<?php
if(isset($_POST['submit']))
{
$str=strtolower($_POST['str']);
$vowels=array('a','e','i','o','u');
$len=strlen($str);
$num=0;
for($i=0;$i<$len;$i++)
{ if(in_array($str[$i],$vowels))
{
$num++;
} }
echo "Number of vowels : $num"; } ?>
SOP 3: Write a PHP program to perform the following operations
on an associative array.
·
Display
elements of an array along with their keys.
·
Display
the size of an array.
·
Delete an element from an array from
the given index.
Array.php
<?php
$m1=array("English"=>"55","Physics"=>"60","Chemistry"=>"70","Biology"=>"85");
echo "<b>Elements of an array along
with their keys :</b>";
echo "<br><br>Your Score :
".$m1['English']." in English";
echo "<br><br>Your Score :
".$m1['Physics']." in Physics";
echo "<br><br>Your Score :
".$m1['Chemistry']." in Chemistry";
echo "<br><br>Your Score :
".$m1['Biology']." in Biology";
echo "<br><br><b>Size of
an Array is : </b>".count($m1);
array_splice($m1,0,1);
echo "<br><br><b>After
deleting array is : </b>";
foreach ($m1 as $x => $x_value) {
echo "<br><br>Key = ".$x." , Value =
".$x_value;
echo "<br>";
}
?>
SOP 4: Write a PHP program to save marks of English, Hindi,
Marathi, Maths and Information Technology in an array. Display marks of
individual subject along with total marks and percentage.
Array1.html
<!DOCTYPE
html>
<html>
<head>
<title>SOP
4</title>
</head>
<body>
<?php
$marks=array("English"=>"60","Hindi"=>"78","Marathi"=>"74","Maths"=>"85","Information
Technology"=>"96");
$t=0;
$x=0;
$c=count($marks);
foreach($marks
as $x=>$x_value)
{
echo
"<br><br> ".$x." = ".$x_value;
$t=$t+$marks[$x];
}
$p=$t*100/500;
echo
"<br><br>Total is : $t";
echo
"<br><br>Percentage is : $p";
?>
</body>
</html>
SOP 5: Write a php program to save marks of English, Hindi,
Marathi, Maths and Information Technology in an array for 5 students and
display totals marks and percentage of each student s using ‘foreach’.
SOP 6 : Write a program using PHP to calculate Electricity bill by
accepting the limits.
·
For
first 100 units - Rs. 4
·
For
next 100 units - Rs. 5
·
For
next all units - Rs. 6
Bill.html
<!DOCTYPE
html>
<html>
<head>
<title>Bill
Form</title>
</head>
<body>
<h1
align="center">Electricity Bill</h1>
<form
method="post" action="bill.php">
Enter
number of units : <input type="text" name="units"
placeholder=""> <br>
<input
type="submit" name="submit" value="Calculate
Bills">
</form>
</body>
</html>
bill.php
<?php
if(isset($_POST['submit']))
{
$units=($_POST['units']);
if($units<=100)
{
$b=$units*4;
echo
"Your bill amount is : ".$b;
}
else
{
if($units<=200)
{
$b=400+($units-100)*5;
echo
"Your bill amount is : ".$b;
}
else
{
$b=400+500+($units-200)*6;
echo
"Your bill amount is : ".$b;
}
}
}
?>
SOP 7: Write
a PHP program to insert a roll number and student name in a database (use
postgreSql data to create database). Accept roll number and name from the user.
0 comments:
Post a Comment