Google Ad
<!DOCTYPE html> Output : 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. <html> Output <?php foreach($age as $x => $x_value) { //Delete an element from an array from the given index Output 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 <?php $subject_marks = array('English' =>56 ,'Hindi' =>76, echo "English : ".$subject_marks['English']; Output <!DOCTYPE html> if($units <= 100) { Output <!DOCTYPE html> $connect = mysqli_connect($host_name, $user_name,$password); if ($result) { ?> OutputHSC Server Side Scripting (PHP) SOP Practicals
with codes and output
Write a PHP program to check if a person is eligible to vote or not. The program should include the following-
Answer:-
<html>
<head>
<title>Eligible to Vote or not</title>
</head>
<body>
<form action="" method="post">
Enter a no :
<input type="text" name="t1" placeholder="Enter a number">
<br><input type="submit" name="submit" value="submit">
</form>
<?php
if (isset($_POST['submit'])) {
vote();
}
function vote() {
$a = $_POST['t1'];
intval($a);
if($a>=18){
echo "You are Eligible for Vote";
}
else{
echo "You are not Eligible for Vote";
}
}
?>
</body>
</html>Answer:-
<body>
<h2>Find Number of Vowels in a String</h2>
<form action="" method="post">
<input type="text" name="string" />
<input type="submit" />
</form>
</body>
</html>
<?php if($_POST)
{
$string = strtolower($_POST['string']);
$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 "Number of vowels : ".$num;
} ?>
Write a PHP program to perform the following operations on an associative array.
Answer:-
//Display elements of an array along with their keys
$age = array("Ramesh"=>"51", "Rakesh"=>"32", "RAhul"=>"23");
echo "Key = " . $x . ", Value = " . $x_value;
echo "<br>";
}
//Display the size of an array
echo "<br>Size of Array is : ".count($age)."<br>";
$data = array(1,2,3,4,5);
for ($i=0; $i < count($data); $i++) {
echo " ".$data[$i];
}
unset($data[1]);
echo "<br>Elements After Deleting : <br>";
for ($i=0; $i < count($data); $i++) {
echo " ".$data[$i];
}
?>Answer:-
'Marathi'=>56,'Maths' =>57 ,'IT'=>78);
$total_marks = $subject_marks['English'] +
$subject_marks['Hindi'] + $subject_marks['Marathi'] +
$subject_marks['Maths'] + $subject_marks['IT'];
echo "<br>Hindi : ".$subject_marks['Hindi'];
echo "<br>Marathi : ".$subject_marks['Marathi'];
echo "<br>Maths : ".$subject_marks['Maths'];
echo "<br>IT : ".$subject_marks['IT'];
echo "<br><br>Total : ".$total_marks;
$percentage = $total_marks/5;
echo "<br>Percentage : ".$percentage;
?>Write a program using PHP to calculate Electricity bill by accepting the limits.
Answer:-
<head>
<title>Calculate Electricity Bill</title>
</head>
<?php
$result_str = $result = '';
if (isset($_POST['unit-submit'])) {
$units = $_POST['units'];
if (!empty($units)) {
$result = calculate_bill($units);
$result_str = 'Total amount of ' . $units . ' - ' . $result;
}
}
function calculate_bill($units) {
$unit_cost_first = 4;
$unit_cost_second = 5;
$unit_cost_third = 6;
$bill = $units * $unit_cost_first;
}
else if($units > 100 && $units <= 200) {
$temp = 100 * $unit_cost_first;
$remaining_units = $units - 100;
$bill = $temp + ($remaining_units * $unit_cost_second);
}
else {
$temp = (100 * 4) + (100 * $unit_cost_second) + (100 * $unit_cost_third);
$remaining_units = $units - 200;
$bill = $temp + $remaining_units ;
}
return number_format((float)$bill, 2, '.', '');
}
?>
<body>
<div id="page-wrap">
<h1>Php - Calculate Electricity Bill</h1>
<form action="" method="post" id="quiz-form">
<input type="number" name="units" id="units" placeholder="Please enter no. of Units" />
<input type="submit" name="unit-submit" id="unit-submit" value="Submit" />
</form>
<div>
<?php echo '<br />' . $result_str; ?>
</div>
</div>
</body>
</html>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.
Answer:-
<html>
<body>
<h1>Students Detail</h1>
<form action="" method="post">
Enter roll no : <br>
<input type="text" name="r1"><br>
Enter your name : <br>
<input type="text" name="t1"><br>
<input type="submit" name="submit" value="submit">
</form>
<?php
$host_name="localhost";
$user_name="root";
$password="";
if (isset($_POST['submit'])) {
$roll_no=$_POST['r1'];
$name=$_POST['t1'];
$sql = "insert into students_table values('".$roll_no."','".$name."')";
$result = mysqli_query($connect,$sql);
echo "Data inserted";
}
else{
echo "Not inserted";
}
}
</body>
</html>