Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.
: 48
Objective 9: Write a JavaScript code to change the background content on button click .
HTML Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Change Background</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 20%;
#changeBtn {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
</style>
</head>
<body>
<h1>Click the Button to Change the Background</h1>
<button id="changeBtn">Change Background</button>
<script>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
const colors = [
"#87CEEB", // Sky Blue
"#4169E1", // Royal Blue
"#1E90FF", // Dodger Blue
"#6495ED", // Cornflower Blue
"#00CED1", // Turquoise Blue
"#000080", // Navy Blue
"#4682B4", // Steel Blue
"#ADD8E6" // Light Blue
];
const button = [Link]('changeBtn');
[Link]('click', () => {
const randomColor = colors[[Link]([Link]() * [Link])];
[Link] = randomColor;
});
</script>
</body>
</html>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
Objective 10: Write a JavaScript code to create four functions addition, subtraction ,
multiplication , division .create two buttons for submit and reset the output must be
displayed in two Text fields.
HTML Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
.input-field {
margin: 10px;
}
#output, #result {
margin: 10px;
width: 200px;
text-align: center;
}
</style>
</head>
<body>
<h1>Simple Calculator</h1>
<div>
<input type="number" id="num1" class="input-field" placeholder="Enter first number">
<input type="number" id="num2" class="input-field" placeholder="Enter second number">
</div>
<div>
<select id="operation" class="input-field">
<option value="add">Addition(+)</option>
<option value="subtract">Subtraction(-)</option>
<option value="multiply">Multiplication(x)</option>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
<option value="divide">Division(/)</option>
</select>
</div>
<div>
<button onclick="performOperation()">Submit</button>
<button onclick="resetFields()">Reset</button>
</div>
<div>
<input type="text" id="output" placeholder="Operation" readonly>
<input type="text" id="result" placeholder="Result" readonly>
</div>
<script>
function performOperation() {
const num1 = parseFloat([Link]('num1').value);
const num2 = parseFloat([Link]('num2').value);
const operation = [Link]('operation').value;
if (isNaN(num1) || isNaN(num2)) {
alert('Please enter valid numbers');
return;
}
let result;
switch (operation) {
case 'add':
result = num1 + num2;
break;
case 'subtract':
result = num1 - num2;
break;
case 'multiply':
result = num1 * num2;
break;
case 'divide':
if (num2 === 0) {
alert('Division by zero is not allowed');
return;
}
result = num1 / num2;
break;
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
default:
result = 'Invalid Operation';
}
[Link]('output').value = `Operation: ${operation}`;
[Link]('result').value = `Result: ${result}`;
}
function resetFields() {
[Link]('num1').value = '';
[Link]('num2').value = '';
[Link]('operation').value = 'add'; // Reset dropdown to default
[Link]('output').value = '';
[Link]('result').value = '';
}
</script>
</body>
</html>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
Objective 11: Write an HTML code to demonstrate the use of hover selector with <a> tag
using CSS.
HTML Code:
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hover Selector Example</title>
<style>
a{
text-decoration: none;
color: #007BFF;
font-size: 18px;
padding: 10px 20px;
border: 2px solid #007BFF;
border-radius: 5px;
}
a:hover {
background-color: #007BFF;
color: white;
transform: scale(1.1);
}
</style>
</head>
<body>
<h1>Hover Selector with <a> Tag</h1>
<p>Hover over the link below to see the effect:</p>
<a href="[Link] target="_blank">Visit Example</a>
</body>
</html>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
Objective 12: Write an HTML code to display a drop down menu(list) on a mouse-hover
event (using hover selector) on the web page .
HTML Code:
<!DOCTYPE html>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hover Dropdown Menu</title>
<style>
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-button {
background-color: #007BFF;
color: white;
padding: 10px 20px;
font-size: 16px;
border: none;
border-radius: 5px;
cursor: pointer;
}
.dropdown-content {
display: none;
position: absolute;
background-color: white;
min-width: 150px;
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);
border-radius: 5px;
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 10px 15px;
text-decoration: none;
display: block;
border-bottom: 1px solid #f1f1f1;
}
.dropdown-content a:hover {
background-color: #f1f1f1;
}
.dropdown:hover .dropdown-content {
display: block;
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
</style>
</head>
<body>
<h1>Dropdown Menu Example</h1>
<p>Hover over the button below to display the dropdown menu:</p>
<div class="dropdown">
<button class="dropdown-button">Hover Me</button>
<div class="dropdown-content">
<a href="#option1">Option 1</a>
<a href="#option2">Option 2</a>
<a href="#option3">Option 3</a>
</div>
</div>
</body>
</html>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
Objective 13: Create student registration webpage using HTML form objects.
HTML Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Registration</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}
.container {
width: 50%;
margin: 50px auto;
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
color: #333;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input, select, textarea {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
}
button {
background-color: #5cb85c;
color: white;
padding: 10px 15px;
border: none;
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #4cae4c;
}
</style>
</head>
<body>
<div class="container">
<h1>Student Registration Form</h1>
<form action="/submit_registration" method="post">
<div class="form-group">
<label for="fullName">Full Name</label>
<input type="text" id="fullName" name="fullName"
placeholder="Enter your full name" required>
</div>
<div class="form-group">
<label for="dob">Date of Birth</label>
<input type="date" id="dob" name="dob" required>
</div>
<div class="form-group">
<label for="gender">Gender</label>
<select id="gender" name="gender" required>
<option value="">Select</option>
<option value="male">Male</option>
<option value="female">Female</option>
<option value="other">Other</option>
</select>
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" id="email" name="email" placeholder="Enter your email"
required>
</div>
<div class="form-group">
<label for="phone">Phone Number</label>
<input type="tel" id="phone" name="phone" placeholder="Enter your phone number"
required>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
</div>
<div class="form-group">
<label for="address">Address</label>
<textarea id="address" name="address" rows="3" placeholder="Enter your address"
required></textarea>
</div>
<div class="form-group">
<label for="course">Course</label>
<select id="course" name="course" required>
<option value="">Select your course</option>
<option value="cs">Computer Science</option>
<option value="it">Information Technology</option>
<option value="mech">Mechanical Engineering</option>
<option value="civil">Civil Engineering</option>
</select>
</div>
<button type="submit">Register</button>
</form>
</div>
</body>
</html>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
Objective 14: Write a JavaScript to validate inputs to a form consists of four different
functions:
a) Email validation will check to see if a value lives up to the general syntax of an [Link]
validate it with @ .
b) Empty validation will check to see if a field is empty or not.
c) Username validation will check to see if a value consists of a number , a capital letter ,a
small letter and length should be greater than 8 character.
d) A proper alert box should be displayed if the user doesn’t enter the value in the above
format.
HTML Code:
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Validation</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
}
input {
padding: 8px;
width: 300px;
font-size: 14px;
}
</style>
</head>
<body>
<h1>Form Validation</h1>
<form id="myForm">
<div class="form-group">
<label for="email">Email:</label>
<input type="text" id="email" placeholder="Enter your email">
</div>
<div class="form-group">
<label for="username">Username:</label>
<input type="text" id="username" placeholder="Enter your username">
</div>
<div class="form-group">
<button type="button" onclick="validateForm()">Submit</button>
</div>
</form>
<script>
function validateEmail(email) {
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return [Link](email);
}
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
function validateUsername(username) {
const usernamePattern = /^(?=.*[A-Z])(?=.*[a-z])(?=.*\d).{8,}$/;
return [Link](username);
}
function validateForm() {
const email = [Link]('email').[Link]();
const username = [Link]('username').[Link]();
let errors = [];
if (email === '') {
[Link]('Email cannot be empty.');
} else if (!validateEmail(email)) {
[Link]('Please enter a valid email address.');
}
if (username === '') {
[Link]('Username cannot be empty.');
} else if (!validateUsername(username)) {
[Link](
'Username must contain at least one number, one uppercase letter, one lowercase letter,
and be at least 8 characters long.'
);
}
if ([Link] > 0) {
alert([Link]('\n'));
} else {
alert('Form submitted successfully!');
}
}
</script>
</body>
</html>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
Objective 15: Write a JavaScript to validate a password field for:
a) Minimum length of password should be greater than 6 characters
b) There should be two fields for password and none of the field should be left empty
c) Both the password should be same
d) The verification should be done on button click .
A proper alert box should be displayed if the user doesn’t enter the values in the above
format.
HTML Code:
<!DOCTYPE html>
<html lang="en">
<head>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Password Validation</title>
<link rel="stylesheet" href="[Link]
css/[Link]">
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
}
input {
padding: 8px;
width: 300px;
font-size: 14px;
}
.password-container {
position: relative;
width: 300px;
}
.eye-icon {
cursor: pointer;
position: absolute;
right: 10px;
top: 65%;
transform: translateY(-50%);
}
</style>
</head>
<body>
<h1>Password Validation</h1>
<form id="passwordForm">
<div class="form-group password-container">
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
<label for="password1">Password:</label>
<input type="password" id="password1" placeholder="Enter your password">
<i class="fas fa-eye eye-icon" onclick="togglePasswordVisibility('password1')"></i>
</div>
<div class="form-group password-container">
<label for="password2">Confirm Password:</label>
<input type="password" id="password2" placeholder="Confirm your password">
<i class="fas fa-eye eye-icon" onclick="togglePasswordVisibility('password2')"></i>
</div>
<div class="form-group">
<button type="button" onclick="validatePassword()">Verification</button>
</div>
</form>
<script>
function togglePasswordVisibility(id) {
const passwordField = [Link](id);
const type = [Link] === "password" ? "text" : "password";
[Link] = type;
}
function validatePassword() {
const password1 = [Link]('password1').[Link]();
const password2 = [Link]('password2').[Link]();
let errors = [];
if (password1 === '') {
[Link]('Password field cannot be empty.');
}
if (password2 === '') {
[Link]('Confirm Password field cannot be empty.');
}
if ([Link] > 0 && [Link] <= 6) {
[Link]('Password must be greater than 6 characters.');
}
if (password1 !== '' && password2 !== '' && password1 !== password2) {
[Link]('Passwords do not match.');
}
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
if ([Link] > 0) {
alert([Link]('\n'));
} else {
alert('Password validated successfully!');
}
}
</script>
</body>
</html>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
Objective 16: Write a program in JavaScript to concatenate two strings.
HTML Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, ini al-scale=1.0">
<title>Concatenate Strings</title>
</head>
<body>
<h2>Concatenate Two Strings</h2>
<p>Enter two strings to concatenate:</p>
<form name="concatForm">
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
<label for="string1">String 1: </label>
<input type="text" id="string1" name="string1"><br><br>
<label for="string2">String 2: </label>
<input type="text" id="string2" name="string2"><br><br>
<input type="bu on" value="Concatenate" onclick="concatenateStrings()">
</form>
<h3>Result:</h3>
<p id="result"></p>
<script>
function concatenateStrings() {
var str1 = [Link];
var str2 = [Link];
var result = str1 + " " + str2;
[Link]("result").innerText = "Concatenated String: " + result;
}
</script>
</body>
</html>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
Objective 17: Write a program in JavaScript to implement any 5 string methods .
HTML Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>String Methods in JavaScript</title>
</head>
<body>
<h2>Demonstrating 5 String Methods in JavaScript</h2>
<form name="stringForm">
<label for="inputString">Enter a String: </label>
<input type="text" id="inputString" name="inputString"><br><br>
<input type="button" value="Show String Methods" onclick="stringMethods()">
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
</form>
<h3>Results:</h3>
<p id="lengthResult"></p>
<p id="uppercaseResult"></p>
<p id="substringResult"></p>
<p id="replaceResult"></p>
<p id="includesResult"></p>
<script>
function stringMethods() {
var str = [Link];
var length = [Link];
var uppercase = [Link]();
var substring = [Link](0, 5);
var replaced = [Link]("JavaScript", "JS");
var includesWord = [Link]("JavaScript");
[Link]("lengthResult").innerText = "Length of String: " + length;
[Link]("uppercaseResult").innerText = "Uppercase String: " + uppercase;
[Link]("substringResult").innerText = "Substring (First 5 chars): " +
substring;
[Link]("replaceResult").innerText = "Replaced String: " + replaced;
[Link]("includesResult").innerText = "Contains 'JavaScript': " +
includesWord;
}
</script>
</body>
</html>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
Objective 18: Write a program in JavaScript to print the square of the first natural numbers.
HTML Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Square of Natural Numbers</title>
</head>
<body>
<h2>Print the Square of the First n Natural Numbers</h2>
<form name="squareForm">
<label for="number">Enter a number (n): </label>
<input type="number" id="number" name="number" min="1" required><br><br>
<input type="button" value="Print Squares" onclick="printSquares()">
</form>
<h3>Squares of Natural Numbers:</h3>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
<ul id="result"></ul>
<script>
function printSquares() {
var n = [Link];
if (n <= 0) {
alert("Please enter a number greater than 0.");
return;
}
var result = [Link]("result");
[Link] = "";
for (var i = 1; i <= n; i++) {
var square = i * i;
var listItem = [Link]("li");
[Link] = "Square of " + i + " is: " + square;
[Link](listItem);
}
}
</script>
</body>
</html>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
Objective 19: Write a program in JavaScript to print the cube of a number take value from the
user.
HTML Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cube of a Number</title>
</head>
<body>
<h2>Print the Cube of a Number</h2>
<form name="cubeForm">
<label for="number">Enter a number: </label>
<input type="number" id="number" name="number" required><br><br>
<input type="button" value="Calculate Cube" onclick="calculateCube()">
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
</form>
<h3>Result:</h3>
<p id="result"></p>
<script>
function calculateCube() {
var num = [Link];
if (isNaN(num) || num === "") {
alert("Please enter a valid number.");
return;
}
var cube = num * num * num;
[Link]("result").innerText = "Cube of " + num + " is: " + cube;
}
</script>
</body>
</html>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
Objective 20: Write a program in JavaScript to create a user defined array.
HTML Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Defined Array</title>
</head>
<body>
<h2>Create a User Defined Array</h2>
<form name="arrayForm">
<label for="arraySize">Enter the number of elements in the array: </label>
<input type="number" id="arraySize" name="arraySize" min="1" required><br><br>
<input type="button" value="Create Array" onclick="createArray()">
</form>
<h3>Array Elements:</h3>
<ul id="arrayResult"></ul>
<script>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
function createArray() {
var size = [Link];
if (size <= 0 || isNaN(size)) {
alert("Please enter a valid size greater than 0.");
return;
}
var userArray = [];
for (var i = 0; i < size; i++) {
var element = prompt("Enter element " + (i + 1) + " of the array:");
[Link](element);
}
var result = [Link]("arrayResult");
[Link] = "";
for (var i = 0; i < [Link]; i++) {
var listItem = [Link]("li");
[Link] = "Element " + (i + 1) + ": " + userArray[i];
[Link](listItem);
}
}
</script>
</body>
</html>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
Objective 21: Write a program in JavaScript to implement any five methods of an array.
HTML Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Array Methods in JavaScript</title>
</head>
<body>
<h2>Demonstrating 5 Array Methods in JavaScript</h2>
<form name="arrayForm">
<label for="inputArray">Enter comma-separated values for the array: </label>
<input type="text" id="inputArray" name="inputArray" placeholder="e.g.,
1,2,3,4,5"><br><br>
<input type="button" value="Show Array Methods" onclick="arrayMethods()">
</form>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
<h3>Results:</h3>
<ul id="result"></ul>
<script>
function arrayMethods() {
var input = [Link];
var arr = [Link](",");
var numArray = [Link](Number);
[Link](100);
var poppedElement = [Link]();
var shiftedElement = [Link]();
var containsValue = [Link](5);
var result = [Link]("result");
[Link] = "";
var methodsResult = [
"Original array: " + [Link](", "),
"Converted to numbers: " + [Link](", "),
"Array after pushing 100: " + [Link](", "),
"Array after popping the last element (popped value: " + poppedElement + "): " +
[Link](", "),
"Array after shifting the first element (shifted value: " + shiftedElement + "): " +
[Link](", "),
"Does the array contain 5? " + containsValue
];
[Link](function(item) {
var listItem = [Link]("li");
[Link] = item;
[Link](listItem);
});
}
</script>
</body>
</html>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
Objective 22: Write a program in JavaScript to show alert() , confirm() ,prompt().
HTML Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Alert, Confirm, and Prompt Example</title>
</head>
<body>
<h2>Demonstrating JavaScript Dialog Boxes</h2>
<button onclick="showAlert()">Show Alert</button><br><br>
<button onclick="showConfirm()">Show Confirm</button><br><br>
<button onclick="showPrompt()">Show Prompt</button><br><br>
<h3>Results:</h3>
<div id="result"></div>
<script>
function showAlert() {
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
alert("This is an alert box!");
}
function showConfirm() {
var result = confirm("Do you want to continue?");
if (result) {
[Link]("result").innerText = "You clicked OK.";
} else {
[Link]("result").innerText = "You clicked Cancel.";
}
}
function showPrompt() {
var name = prompt("Please enter your name:");
if (name != null && [Link]() !== "") {
[Link]("result").innerText = "Hello, " + name + "!";
} else {
[Link]("result").innerText = "You didn't enter a name.";
}
}
</script>
</body>
</html>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
Objective 23: Write a program in PHP to swap two integer values.
PHP Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Swapping</title>
</head>
<body>
<h2> Swapping using php </h2>
<?php
$a = 5;
$b = 10;
echo "Before swapping: a = $a, b = $b<br>";
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
$temp = $a;
$a = $b;
$b = $temp;
echo "After swapping: a = $a, b = $b<br>";
?>
</body>
</html>
Objective 24: Write a PHP program to :
a) Transform a string to all uppercase le ers.
b) Transform a string to all lowercase le ers.
c) Make a string’s first le er uppercase.
d) Make a string’s first le er lowercase and rest of the le ers to uppercase.
PHP Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>String Transformations</title>
</head>
<body>
<h2>String Transformation Examples</h2>
<?php
$string = "Hello World";
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
$uppercase = strtoupper($string);
$lowercase = strtolower($string);
$ucfirst = ucfirst(strtolower($string));
$specialCase = lcfirst(strtoupper($string));
echo "<p>Original String: $string</p>";
echo "<p>a) All Uppercase: $uppercase</p>";
echo "<p>b) All Lowercase: $lowercase</p>";
echo "<p>c) First Letter Uppercase: $ucfirst</p>";
echo "<p>d) First Letter Lowercase, Rest Uppercase: $specialCase</p>";
?>
</body>
</html>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
Objective 25: Write a PHP program for showing the use of all the operators in PHP.
PHP Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP Operators Example</title>
</head>
<body>
<h2>Demonstrating PHP Operators</h2>
<?php
$a = 10;
$b = 5;
$c = "10";
echo "<h3>Arithmetic Operators</h3>";
echo "Addition: $a + $b = " . ($a + $b) . "<br>";
echo "Subtraction: $a - $b = " . ($a - $b) . "<br>";
echo "Multiplication: $a * $b = " . ($a * $b) . "<br>";
echo "Division: $a / $b = " . ($a / $b) . "<br>";
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
echo "Modulus: $a % $b = " . ($a % $b) . "<br>";
echo "Exponentiation: $a ** $b = " . ($a ** $b) . "<br>";
echo "<h3>Assignment Operators</h3>";
$x = 20;
echo "Initial value: $x<br>";
$x += 10;
echo "After += 10: $x<br>";
$x -= 5;
echo "After -= 5: $x<br>";
$x *= 2;
echo "After *= 2: $x<br>";
$x /= 2;
echo "After /= 2: $x<br>";
$x %= 3;
echo "After %= 3: $x<br>";
echo "<h3>Comparison Operators</h3>";
echo "$a == $c: " . var_export($a == $c, true) . "<br>";
echo "$a === $c: " . var_export($a === $c, true) . "<br>";
echo "$a != $b: " . var_export($a != $b, true) . "<br>";
echo "$a !== $c: " . var_export($a !== $c, true) . "<br>";
echo "$a > $b: " . var_export($a > $b, true) . "<br>";
echo "$a < $b: " . var_export($a < $b, true) . "<br>";
echo "<h3>Logical Operators</h3>";
echo "($a > $b && $b > 0): " . var_export($a > $b && $b > 0, true) . "<br>";
echo "($a > $b || $b < 0): " . var_export($a > $b || $b < 0, true) . "<br>";
echo "!($a < $b): " . var_export(!($a < $b), true) . "<br>";
echo "<h3>Increment/Decrement Operators</h3>";
$i = 5;
echo "Initial value: $i<br>";
echo "Pre-increment: " . ++$i . "<br>";
echo "Post-increment: " . $i++ . "<br>";
echo "After post-increment: $i<br>";
echo "Pre-decrement: " . --$i . "<br>";
echo "Post-decrement: " . $i-- . "<br>";
echo "After post-decrement: $i<br>";
echo "<h3>String Operators</h3>";
$str1 = "Hello";
$str2 = "World";
echo "Concatenation: $str1 . $str2 = " . ($str1 . " " . $str2) . "<br>";
$str1 .= " PHP";
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
echo "Concatenation with assignment: $str1<br>";
echo "<h3>Array Operators</h3>";
$arr1 = ["a" => 1, "b" => 2];
$arr2 = ["c" => 3, "d" => 4];
echo "Union: ";
print_r($arr1 + $arr2);
echo "<br>";
echo "Equality: " . var_export($arr1 == $arr2, true) . "<br>";
echo "Inequality: " . var_export($arr1 != $arr2, true) . "<br>";
echo "<h3>Bitwise Operators</h3>";
echo "$a & $b = " . ($a & $b) . "<br>";
echo "$a | $b = " . ($a | $b) . "<br>";
echo "$a ^ $b = " . ($a ^ $b) . "<br>";
echo "~$a = " . (~$a) . "<br>";
echo "$a << 1 = " . ($a << 1) . "<br>";
echo "$a >> 1 = " . ($a >> 1) . "<br>";
echo "<h3>Null Coalescing Operator</h3>";
$var = null;
echo "\$var ?? 'Default': " . ($var ?? 'Default') . "<br>";
echo "<h3>Spaceship Operator</h3>";
echo "$a <=> $b = " . ($a <=> $b) . "<br>";
echo "$b <=> $a = " . ($b <=> $a) . "<br>";
?>
</body>
</html>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
Objective 26: Write a PHP program to implement Super global variable.
PHP Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GET and POST</title>
</head>
<body>
<h2>Submit Your Information</h2>
<form action="" method="get" id="infoForm">
<label>Number: <input type="text" name="u1" required></label><br><br>
<label>Course: <input type="text" name="u2" required></label><br><br>
<label>Email: <input type="email" name="u3" required></label><br><br>
<label>Method:
<select onchange="[Link]('infoForm').method = [Link]">
<option value="get">GET</option>
<option value="post">POST</option>
</select>
</label><br><br>
<button type="submit">Submit</button>
</form>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48
<?php
$data = $_SERVER['REQUEST_METHOD'] === 'POST' ? $_POST : $_GET;
if (!empty($data)) {
echo "<h3>Submitted Data:</h3>";
echo "Number: " . htmlspecialchars($data['u1'] ?? '') . "<br>";
echo "Course: " . htmlspecialchars($data['u2'] ?? '') . "<br>";
echo "Email: " . htmlspecialchars($data['u3'] ?? '') . "<br>";
}
?>
</body>
</html>
Name: Rishav Gusain Course/Sec: BCA/F1 Roll No.: 48