NAME – ABHISHEK SHAHI
COURSE – BCA 4 ,B1
ROLL NO - 01
PROBLEM STATEMENT (18) :- Write a PHP script to:
a) transform a string all uppercase letters.
b) transform a string all lowercase letters.
c) make a string's first character uppercase.
d) make a string's first character of all the words uppercase
OBJECTIVE :- To understand how to change case of the letters.
SOURCE CODE :-
<?php
// Sample string
$string = "hello world";
// a) Transform a string to all uppercase letters
$upper = strtoupper($string);
echo "Uppercase: " . $upper . "<br>";
// b) Transform a string to all lowercase letters
$lower = strtolower($string);
echo "Lowercase: " . $lower . "<br>";
// c) Make a string's first character uppercase
$ucfirst = ucfirst($string);
echo "First character uppercase: " . $ucfirst . "<br>";
// d) Make a string's first character of all the words uppercase
$ucwords = ucwords($string);
echo "First character of all words uppercase: " . $ucwords . "<br>";
?>
NAME – ABHISHEK SHAHI
COURSE – BCA 4 ,B1
ROLL NO - 01
OUTPUT:-
PROBLEM STATEMENT (19) :- Write a php code to show the use of at least five string
variables.
OBJECTIVE :- To learn different string functions in PHP.
SOURCE CODE :-
<?php
$string1 = "Hello";
$string2 = "World";
$string3 = "PHP";
$string4 = "is";
$string5 = "awesome";
echo $string1 . " " . $string2 . "\n"; // Concatenation
echo $string3 . " " . $string4 . " " . $string5 . "<br>";
echo "Length of string1: " . strlen($string1) . "<br>";
echo "Uppercase string2: " . strtoupper($string2) . "<br>";
NAME – ABHISHEK SHAHI
COURSE – BCA 4 ,B1
ROLL NO - 01
echo "Lowercase string5: " . strtolower($string5) . "<br>";
?>
OUTPUT:-
PROBLEM STATEMENT (20) :- Write a program in php to sort an associative array in
descending order..
OBJECTIVE :- To understand how to sort an array in PHP.
SOURCE CODE :-
<?php
$assoc_array = array("a" => 1, "b" => 3, "c" => 2, "d" => 5, "e" => 4);
arsort($assoc_array);
print_r($assoc_array);
?>
NAME – ABHISHEK SHAHI
COURSE – BCA 4 ,B1
ROLL NO - 01
PROBLEM STATEMENT (21) :- Write a PHP code for showing the use of all the
operators in PHP.
OBJECTIVE :- To understand the different operators in PHP .
SOURCE CODE :-
<?php
$a = 10;
$b = 20;
// Arithmetic Operators
echo "Addition: " . ($a + $b) . "\n";
echo "Subtraction: " . ($a - $b) . "\n";
echo "Multiplication: " . ($a * $b) . "\n";
echo "Division: " . ($a / $b) . "\n";
echo "Modulus: " . ($a % $b) . "\n";
// Assignment Operator
$a += 5;
echo "Assignment after addition: " . $a . "\n";
// Comparison Operators
echo "Equal: " . var_export($a == $b, true) . "\n";
echo "Not Equal: " . var_export($a != $b, true) . "\n";
echo "Greater than: " . var_export($a > $b, true) . "\n";
echo "Less than: " . var_export($a < $b, true) . "\n";
// Logical Operators
NAME – ABHISHEK SHAHI
COURSE – BCA 4 ,B1
ROLL NO - 01
echo "Logical AND: " . var_export($a == 15 && $b == 20, true) . "\n";
echo "Logical OR: " . var_export($a == 15 || $b == 10, true) . "\n";
// Increment/Decrement Operators
$a++;
echo "Increment: " . $a . "\n";
$b--;
echo "Decrement: " . $b . "\n";
?>
NAME – ABHISHEK SHAHI
COURSE – BCA 4 ,B1
ROLL NO - 01
PROBLEM STATEMENT (22) :- To find the sum of digits of a number just add all the
digits.
OBJECTIVE :- To understand the concept of adding all the digit of a number.
SOURCE CODE :-
<?php
function sumOfDigits($number) {
$sum = 0;
while ($number > 0) {
$sum += $number % 10;
$number = (int)($number / 10);
}
return $sum;
}
echo "Sum of digits of 12345: " . sumOfDigits(12345) . "\n";
?>
NAME – ABHISHEK SHAHI
COURSE – BCA 4 ,B1
ROLL NO - 01
PROBLEM STATEMENT (23):- Write a PHP code for showing the use of foreach loop.
OBJECTIVE :- To understand the use of foreach loop in PHP .
SOURCE CODE :-
<?php
$array = array("apple", "banana", "cherry");
foreach ($array as $value)
{ echo $value . "\n";
}
?>
NAME – ABHISHEK SHAHI
COURSE – BCA 4 ,B1
ROLL NO - 01
PROBLEM STATEMENT (24):- Write a PHP program to create a Welcome Cookie.
OBJECTIVE :- To understand how to create welcome cookie in PHP.
SOURCE CODE :-
<?php
$cookie_name = "user";
$cookie_value = "John Doe";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
if(isset($_COOKIE[$cookie_name])) {
echo "Welcome " . $_COOKIE[$cookie_name];
} else {
echo "Welcome guest!";
}
?>
NAME – ABHISHEK SHAHI
COURSE – BCA 4 ,B1
ROLL NO - 01
PROBLEM STATEMENT (25):- create database including all step i.e how to connect
with the database through php
OBJECTIVE :- To understand how to create a database and connect it with PHP .
SOURCE CODE :-
<?php
$servername = "localhost";
$username = "root";
$password = "";
$conn = mysqli_connect($servername, $username, $password);
$sql="CREATE DATABASE manav";mysqli_query($conn,$sql);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
else{
echo"connected successfully";
}
?>
NAME – ABHISHEK SHAHI
COURSE – BCA 4 ,B1
ROLL NO - 01
PROBLEM STATEMENT (26):- Create a database in MYSQL GEHU containing table
course having three fields course name, course_id, and course duration. Write a php code to
insert the values in the table course. (at least 5 records must be inserted)
OBJECTIVE :- To understand how to insert values in database.
SOURCE CODE :-
<?php
$servername = "localhost";
$username = "root";
$password = "";
$database = "GEHU";
$conn = mysqli_connect($servername, $username, $password, $database);
if (!$conn) { die("Connection failed: " .
mysqli_connect_error());
} else {
echo "Database connected successfully<br>";
}
$sql = "CREATE TABLE `Course` (
`course_id` INT NOT NULL AUTO_INCREMENT,
`course_name` VARCHAR(25) NOT NULL,
`course_duration` INT NOT NULL,
PRIMARY KEY (`course_id`)
)";
$result = mysqli_query($conn, $sql
NAME – ABHISHEK SHAHI
COURSE – BCA 4 ,B1
ROLL NO - 01
if ($result) { echo "Table created
successfully!<br>";
} else { echo "Failed: " .
mysqli_error($conn);
}
$sql = "INSERT INTO `Course` (`course_name`, `course_duration`) VALUES
('Computer Science', '4 years'),
('Mechanical Engineering', '4 years'),
('Electrical Engineering', '4 years'),
('Civil Engineering', '4 years'),
('Information Technology', '4 years')";
$result = mysqli_query($conn, $sql);
if ($result) { echo " Data Inserted successfully!<br>";
} else { echo "Failed: " .
mysqli_error($conn);
?>
NAME – ABHISHEK SHAHI
COURSE – BCA 4 ,B1
ROLL NO - 01
NAME – ABHISHEK SHAHI
COURSE – BCA 4 ,B1
ROLL NO - 01
PROBLEM STATEMENT (27):- Create a student form from php and save the student
record and display on browser as well.
OBJECTIVE :- To understand the concept of a form in PHP.
SOURCE CODE :-
<!DOCTYPE html>
<HTML>
<HEAD>
<TITLE>PHP FORM PARSE</TITLE>
</HEAD>
<BODY>
<form action = "run.php" method="post">
Name : <input type="text" name="Name"><br>
Email : <input type="email" name="Email"><br>
<input type="submit">
</form>
</BODY>
</HTML>
<?php if($_SERVER['REQUEST_METHOD'] =='POST') {
echo "<br>Entered Name :".$_POST["Name"];
echo "<br>Entered Email :".$_POST["Email"];
?>
NAME – ABHISHEK SHAHI
COURSE – BCA 4 ,B1
ROLL NO - 01
ABHISHEK SHAHI
02ABHISHEKSHAHI@GMAIL.COM
ABHISHEK
02ABHISHEKSHAHI@GMAIL.COM