p1 -mathematical; expression
<html>
<head>
<title>Mathematical Expression</title>
<script type="text/javascript">
function math_exp()
{
var x=document.form1.exptext.value;
var result=eval(x);
document.form1.resulttext.value=result;
}
</script>
</head>
<body bgcolor="cyan">
<h1 align="center">Evaluating Airthmetic Expressions</h1>
<hr/>
<form align="center" name="form1">
enter any valid expression
<input type="text" name="exptext"/><br/><br/>
<input type="button" value="CALCULATE" onclick="math_exp()"/><br/><br/>
result
<input type="text" name="resulttext"/><br/><br/>
</form>
</body>
</html>
p2- dynamic layer
<html>
<head>
<title>Basic Animation</title>
<style>
#layer1{position:absolute;top:50px;left:50px;}
#layer2{position:absolute;top:50px;left:150px;}
#layer3{position:absolute;top:50px;left:250px;}
</style>
<script type="text/javascript">
function moveImage(layer)
{
var top=window.prompt("Enter Top Value");
var left=window.prompt("Enter Left Value");
document.getElementById(layer).style.top=top+'px';
document.getElementById(layer).style.left=left+'px';
}
</script>
</head>
<body bgcolor="cyan">
<div id="layer1"><img src="C:\Users\hrishikesh\OneDrive\Pictures\Saved Pictures\Ninja.jpg" width ="300" height="300" Onclick="moveImage('layer1')" alt="MyImage"></div>
<div id="layer2"><img src="C:\Users\hrishikesh\OneDrive\Pictures\Saved Pictures\Ninja.jpg" width ="300" height="300"Onclick="moveImage('layer2')" alt="MyImage"></div>
<div id="layer3"><img src="C:\Users\hrishikesh\OneDrive\Pictures\Saved Pictures\Ninja.jpg"width ="300" height="300" Onclick="moveImage('layer3')" alt="MyImage"></div>
</body>
</html>
p3 - N natural numbers
<html>
<head>
<title>Sum Of N Natural Numbers</title>
<script type="text/javascript">
function sum()
{
var num=window.prompt("Enter The Value Of N:");
var n=parseInt(num);
var sum=(n*(n+1))/2;
window.alert("Sum Of First "+n+" Natural Numbers is:"+sum);
}
</script>
</head>
<body bgcolor="cyan">
<h1 align="center">Finding Sum Of N Natural Numbers</h1>
<hr/>
<form align="center">
<input type="button" value="Click Here" onclick="sum();"/>
</form>
</body>
</html>
p4 - Date in words
<html>
<head>
<title> DISPLAY DATE</title>
<script type="text/javascript">
function display()
{
var dateObj=new Date();
var currDate=dateObj.getDate();
var currMonth=dateObj.getMonth();
var currYear=dateObj.getFullYear();
var year="Two Thousand and Twenty Three"
var days=["First" ,"Second" ,"Third","Fourth","Fifth","Sixth","Seventh","Eighth","Ninth","Tenth","Eleventh","Twelfth","Thirteenth","Fourteenth","Fiveteenth","Sixteenth","Seventeenth","Eightteenth","Nineteenth","twentyeth","TwentyFirst","TwentySecond","TwentyThird","TwentyFourth","TwentyFifth","TwentySixth","TwentySeventh","TwentyEighth","TweentyNinth","Thirty","Thirtyfirst"];
var months=["January","Febraury","March","April","May","June","July","August","Sep","Oct","November","December"];
if(currYear==2023)
alert("Today date is ::"+days[currDate-1]+" "+months[currMonth]+" "+year);
else
alert("Today date is ::"+days[currDate-1]+" "+months[currMonth]+" "+currYear);
}
</script>
</head>
<body bgcolor=lightblue>
<h1 align=center>Today's Date</h1>
<hr>
<form align=center>
<input type="button" value="click here" onclick="display()"/>
</form>
</body>
</html>
p5 - stud info
<html>
<head>
<title>Student Marks Report</title>
<script type="text/javascript">
function ShowResult()
{
var name=document.getElementById("name").value;
var cls=document.getElementById("class").value;
var marks1=parseInt(document.getElementById("sub1").value);
var marks2=parseInt(document.getElementById("sub2").value);
var marks3=parseInt(document.getElementById("sub3").value);
var total=marks1+marks2+marks3;
var avg=total/3;
var grade,result;
if(avg>=60)
{
grade="A";
result="First Class";
}
else if(avg<60 && avg>=50)
{
grade="B";
result="Second Class";
}
else if(avg<50 && avg>=40)
{
grade="C";
result="Third Class";
}
else
{
grade="D";
result="Fail";
}
document.write("<body bgcolor=pink>");
document.write("<h2>Students Marks Report</h2>");
document.write("<hr>");
document.write("<b>Name:"+name+"</b><br><br>");
document.write("<b>Class:"+cls+"</b><br><br>");
document.write("<b>Total Marks:"+total+"</b><br/><br/>");
document.write("<b>Average:"+avg+"</b><br/><br/>");
document.write("<b>Grade:"+grade+"</b><br/><br/>");
document.write("<b>Result:"+result+"</b><br/><br/>");
}
</script>
</head>
<body bgcolor="cyan">
<h1 align="center">Student Information</h1>
<hr>
<form>
<table border="5">
<tr><th>Student Data Form</th></tr>
<tr>
<td>Student Name</td>
<td><input type="text" id="name"></td></tr>
<tr>
<td>Class</td>
<td><input type="text" id="class"></td></tr>
<tr>
<td>Subject 1 Marks</td>
<td><input type="text" id="sub1"></td></tr>
<tr>
<td>Subject 2 Marks</td>
<td><input type="text" id="sub2"></td></tr>
<tr>
<td>Subject 3 Marks</td>
<td><input type="text" id="sub3"></td></tr>
</table><br/><br/>
<input type="button" value="show result" onclick="ShowResult()"/>
</form>
</body>
</html>
p6 - emp salary
<html>
<head>
<title> Employee Salary Report </title>
<script type="text/javascript">
function showSalary()
{
var name=document.getElementById("empname").value;
var empno=document.getElementById("empno").value;
var basic = parseInt(document.getElementById("basic").value);
var hra=basic*0.4;
var da=basic*0.6;
gross=basic+hra+da;
var pf=gross*0.13;
var tax=0.2*gross;
var deductions=pf+tax;
var netsalary=gross-deductions;
document.write("<body bgcolor=pink>");
document.writeln("<table border='5'>");
document.writeln("<tr><th colspan=2> Employee Salary Report </th> </tr>");
document.writeln("<tr><td> Employee Name:</td> <td>"+name+"</td></tr>");
document.writeln("<tr><td> Emp No : </td> <td>"+empno+"</td></tr>");
document.writeln("<tr><td> Basic Salary :</td> <td>"+basic+"</td></tr>");
document.writeln("<tr><td> HRA (40 % of basic) </td><td>"+hra+"</td></tr>");
document.writeln("<tr><td> DA (60 % of basic</td> <td>"+da+"</td></tr>");
document.writeln("<tr><td> Gross salary : </td> <td>"+gross+"</td></tr>");
document.writeln("<tr><td> PF ( 13% of the basic )</td><td>"+pf+"</td></tr>");
document.writeln("<tr><td> Tax (20% of the gross) : </td><td>"+tax+"</td></tr>");
document.writeln("<tr><td>Deductions (PF + Tax) </td><td>"+deductions+"</td></tr>");
document.writeln("<tr><td>Net Salary (Gross - Deductions) : </td><td>"+netsalary+"</td></tr>");
document.writeln("</table>"); document.write("</body>");
}
</script>
<body bgcolor="cyan")
<form>
<table border="5">
<tr>
<th colspan=2> Employee Salary Form </th>
</tr> <tr> <td> Employee Name :</td>
<td> <input type="text" id="empname"/></td>
</tr> <tr> <td> Employee Number </td> <td>
<Input Type ="text" id="empno"/> </td> </tr> <tr>
<td> Basic Pay </td>
<td>
<input type=text id=basic /></td>
</tr>
</table>
<br>
<input type=button value="Show Salary" onclick="showSalary()">
</form>
</html>
p7 - BG COLOUR
<html>
<head>
<title>Background Colors change based on the day of the week</title>
</head>
<body>
<h1 style="text-align:center;color:brown;">Background Color Based on Day of the Week</h1>
<form style="text-align:center;" action=" " method="post" >
<h2 style="color:red;" > <strong> Choose Day of the Week :- </strong></h2>
<select name="day">
<option>Monday</option>
<option>Tuesday</option>
<option>Wednesday</option>
<option>Thrusday</option>
<option>Friday</option>
<option>Saturday</option>
<option>Sunday</option>
</select>
<input type="submit" value="ok"/>
<?php
$today = $_POST['day'];
$colors = array(
"Sunday" => "#FEF0C5", // Red
"Monday" => "#00FF00", // Green
"Tuesday" => "#FBFFC4", // Blue
"Wednesday" => "#FF00FF", // Magenta
"Thursday" => "#FFFF00", // Yellow
"Friday" => "#00FFFF", // Cyan
"Saturday" => "#FFA500" // Orange
);
if($today == "Sunday")
{
$bgcolor = $colors[$today];
}
elseif($today == "Monday")
{
$bgcolor = $colors[$today];
}
elseif($today == "Tuesday")
{
$bgcolor = $colors[$today];
}
elseif($today == "Wednesday")
{
$bgcolor = $colors[$today];
}
elseif($today == "Thursday")
{
$bgcolor = $colors[$today];
}
elseif($today == "Friday")
{
$bgcolor = $colors[$today];
}
elseif($today == "Saturday")
{
$bgcolor = $colors[$today];
}
else
{
$bgcolor = "#F0F4F1";
}
print("<body bgcolor=\"$bgcolor\">\n");
?>
<h1 style="color:blue;"><p>Today is <?php echo $today; ?></p></h1>
</form>
</body>
</html>
p8 - prime fibbonic
<?php
function isprime($num)
{
if ($num<=1)
{
return false;
}
for($i=2; $i<=sqrt($num); $i++)
{
if ($num%$i==0)
{
return false;
}
}
return true;
}
function Prime($n)
{
$PrimeNumbers=[];
$count=0;
$i=2;
while ($count<$n)
{
if (isPrime($i))
{
$PrimeNumbers[]=$i;
$count++;
}
$i++;
}
return $PrimeNumbers;
}
function Fibonacci($n)
{
$fibonacciSeries=[];
$first=0;
$second=1;
$fibonacciSeries[]=$first;
$fibonacciSeries[]=$second;
for($i=2; $i<$n; $i++)
{
$next=$first+$second;
$fibonacciSeries[]=$next;
$first = $second;
$second = $next;
}
return $fibonacciSeries;
}
$number_of_primes=10;
$number_of_Terms=10;
$primes=Prime($number_of_primes);
$fibonacci=Fibonacci($number_of_Terms);
echo "Prime Numbers";
echo "<pre>".print_r($primes,True)."</pre>";
echo "Fibonacci Series";
echo "<pre>".print_r($fibonacci, true)."<pre>";
?>
p9 - duplicate
<html>
<head>
<title>Duplicate</title>
</head>
<body>
<?php
function remove_duplicate($list1)
{
$nums_uniques = array_values(array_unique($list1));
return $nums_uniques;
}
$nums = array(1,1,2,2,3,4,5,5);
print_r($nums);
echo "<br/><br/>After Removing Duplicates: <br/><br/>";
print_r(remove_duplicate($nums));
?>
</body>
</html>
p10 - pattern
<?php
$rows=5;
for($i=$rows; $i>=1; $i--)
{
for($j=$rows; $j>$i; $j--)
{
echo " ";
}
for($k=1; $k<=$i; $k++)
{
echo "*";
}
echo "<br>";
}
?>
p11 - searcg by criteria
<?php
$users = [
['id' => 1, 'name' => 'anjali', 'age' => 20, 'email' => 'anjali@gmail.com'],
['id' => 2, 'name' => 'neha', 'age' => 21, 'email' => 'neha@qurail.com'],
['id' => 3, 'name' => 'janu', 'age' => 22, 'email' => 'janu@gmail.com'],
['id' => 4, 'name' => 'vinay', 'age' => 19, 'email' => 'vinay@gmail.com'],
];
function search($data, $criteria, $value)
{
$result = [];
foreach ($data as $item)
{
if ($item[$criteria] == $value)
{
$result[] = $item;
}
}
return $result;
}
$searchcriteria = 'age';
$searchvalue = "19";
$searchresult = search($users, $searchcriteria, $searchvalue);
echo "<h1>Search Results for $searchcriteria = $searchvalue: <br></h1>";
if (count($searchresult) > 0)
{
foreach ($searchresult as $result)
{
echo "Id: " . $result['id'] ,
",<br/> Name: " . $result['name'] ,
",<br/> Age: " . $result['age'] ,
",<br/> Email: " . $result['email'];
}
}
else
{
echo "No result Found";
}
?>
p12 - captha code
<?php
function generateCaptcha($length=6)
{
$characters='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$captcha="";
$charLength=strlen($characters);
for($i=0;$i<$length;$i++)
{
$captcha.=$characters[rand(0,$charLength-1)];
}
$_SESSION['capthcha']=$captcha;
return $captcha;
}
session_start();
$captchaCode=generateCaptcha(6);
echo"Generated Captcha:$captchaCode";
?>
p13 - read and write
<!DOCTYPE html>
<html>
<head>
<title>Read and Write File</title>
</head>
<body>
<h2>Write to File</h2>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<textarea name="content" rows="5" cols="40" placeholder="Enter text to write"></textarea><br><br>
<input type="submit" name="write" value="Write to File">
</form>
<hr>
<h2>Read from File</h2>
<?php
$file='data.txt';
if($_SERVER["REQUEST_METHOD"]=="POST" && isset($_POST['write']))
{
$content=$_POST['content'];
file_put_contents($file, $content, FILE_APPEND | LOCK_EX);
echo "Content written to file successfully!";
}
if (file_exists($file))
{
$content = file_get_contents($file);
echo "<pre>$content</pre>";
}
else
{
echo "File not found!";
}
?>
</body>
</html>
p14 - validate input
<html>
<head>
<style>
.error {color: #FF0001;}
</style>
</head>
<body>
<?php
$nameErr = $emailErr = "";
$name = $email = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if (empty($_POST["name"]))
{
$nameErr = "Name is required";
}
else
{
$name = input_data($_POST["name"]);
if (!preg_match("/^[a-zA-Z]*$/", $name))
{
$nameErr = "Only alphabets and white space are allowed";
}
}
if (empty($_POST["email"]))
{
$emailErr = "Email is required";
} else
{
$email = input_data($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$emailErr = "Invalid email format";
}
}
}
function input_data($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<h2>Registration Form</h2>
<span class="error">* required field </span> <br><br>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
Name: <input type="text" name="name">
<span class="error">* <?php echo $nameErr; ?> </span> <br><br>
E-mail: <input type="text" name="email">
<span class="error">* <?php echo $emailErr; ?> </span> <br><br>
<input type="submit" name="submit" value="Submit"> <br><br>
</form>
<?php
if (isset($_POST['submit']))
{
if ($nameErr == "" && $emailErr == "")
{
echo "<h3color=#FF0001> <b>You have successfully registered.</b></h3>";
echo "<h2>Your Input:</h2>";
echo "Name: " . $name;
echo "<br>";
echo "Email: " . $email;
echo "<br>";
}
else
{
echo "<h3> <b>You didn't fill up the form correctly.</b></h3>";
}
}
?>
</body>
</html>
p15 - cookie
<?php
$cookie_name = "UserID";
$cookie_value = "A1B234C";
$expiration_time = time() + (24 * 3600);
setcookie($cookie_name, $cookie_value, $expiration_time, "/");
echo "Cookie '$cookie_name' is set.<br><br><br>";
if (!isset($_COOKIE[$cookie_name]))
{
echo "Cookie named '$cookie_name' is not set.";
}
else
{
echo "Value of cookie '$cookie_name' is: " . $_COOKIE[$cookie_name];
}
?>
p16 - college website
<!DOCTYPE html>
<html>
<head>
<title>College Website</title>
<style>
body
{
font-family: Arial, sans-serif;
margin: 20px;
}
h1
{
color: #333;
}
P
{
color: #666;
}
</style>
</head>
<body>
<header>
<h1>Welcome to Our College</h1>
</header>
<nav>
<ul>
<li><a href="https://gimsedu.in/">Home</a></li>
<li><a href="https://gimsedu.in/dks-charitable-trust/#">About Us</a></li>
<li><a href="https://gimsedu.in/department-of-computer-applications/">Courses</a></li>
<li><a href="https://gimsedu.in/contact/">Contact</a></li>
</ul>
</nav>
<main>
<section>
<h2>About Our College</h2>
<p>GIMS believes in sustained, well-designed pedagogy & participatory self-reflections with a right synthesis of assertiveness & values in all its endeavors.
The founders of GIMS believe in the moto “Quality education for all at all levels.
Global Institute of Management Sciences (GIMS) is an ambitious venture of D.K.S.Charitable Institute (R). The Institution is situated in a beautiful and picturesque area of Rajarajeshwarinagar on the south eastern part of Bangalore city and affiliated to Bangalore University, recognized by Government of Karnataka and is approved by All India Council of Technical Education (AICTE), New Delhi. The Institute offers Post Graduate degree in Master of Computer Applications (MCA), Master in Business Administration (MBA) and Undergraduate degree in Bachelor of Computer Applications (BCA), Bachelor of Business Administration (BBA) and Bachelor of Commerce (B.Com)..</p>
</section>
<section>
<h2>Available Courses</h2>
<?php
$courses = ['Computer Science', 'Engineering', 'Business', 'Arts', 'Science'];
echo "<ul>";
foreach($courses as $course)
{
echo "<li>$course</li>";
}
echo "</ul>";
?>
</section>
<section>
<h2>Contact Information</h2>
<p>Address: 123 College Avenue, City, Country</p>
<p>Email: info@college.com</p>
<p>Phone: 080-25634869</p>
</section>
</main>
<footer>
<p>©
<?php
echo date("Y");
?>
Our College. All rights reserved.</p>
</footer>
</body> </html>
p17 - exception handling
<?php
try
{
$numerator = 10;
$denominator = 2;
if ($denominator===0)
{
throw new Exception("Division by zero error");
}
$result = $numerator/$denominator;
echo "Result of division:" .$result."<br>";
$dateString ='2023-12-25';
$dateFormat='Y-m-d';
$date = DateTime::createFromFormat($dateFormat, $dateString);
if (!$date || $date->format($dateFormat) !== $dateString)
{
throw new Exception("Invalid date format");
}
echo "Date is valid: ". $dateString;
}
catch (Exception $e)
{
echo "Error: ". $e->getMessage();
}
?>
THE END
ALL THE BEST
Comments
Post a Comment