Assign 1
<!doctype html>
<html>
<body>
<h2>List of Indian States with thier capitals</h2>
<ol>
<li>Delhi</li>
<ul><li>New Delhi</li></ul>
<li>Haryana</li>
<ul><li>Chandighard</li></ul>
<li>Gujarat</li>
<ul><li>Gandhinagar</li></ul>
<li>Rajasthan</li>
<ul><li>Jaipur</li></ul>
<li>Maharashtra</li>
<ul><li>Jaipur</li></ul>
<li>Uttarpradesh</li>
<ul><li>Lucknow</li></ul>
</ol>
</body>
</html>
<!doctype html>
<html>
<body>
<h1 align="center"> List of Books</h1>
<table border =1 width=500 height=200 cellspacing=0 align="center">
<tr>
<th rowspan=2> Item Number</th>
<th rowspan=2> Name </th>
<th colspan=2> Price</th>
</tr>
<tr>
<th> RS</th> <th> Paise</th>
</tr>
<tr align="center">
<td> 1 </td> <td> Programming in Python</td><td>500</td><td>50</td>
</tr>
<tr align="center">
<td> 2 </td> <td> Programming in Java</td><td> 345</td><td>00</td>
</tr>
</table>
</body>
</html>
<html>
<head>
<title> A3 </title>
</head>
<body>
<table border=1 width=100% height=100%>
<tr>
<td colspan=2>
<h1> This is a header</h1></td>
</tr>
<tr height=100%>
<td width=30%> Look in the box at the right for some infomation</td>
<td> Here is some infomation</td>
</tr>
<tr>
<td colspan=2> <footer style="font-size:35px;font-weight:bold;"> This is a
footer</footer></td>
</tr>
</table
</body>
</html>
Operating system info form
<html>
<head>
<style>
h2{
font-family:"algerian";
color:red;
}
form {
background-color:pink;
}
button{
border-radius:40px;
background-color:white;
}
</style>
</head>
<body>
<form action="redistration.php">
<h2> Operating System Information</h2>
Enter your name:<input type="text" name="name"><br><br>
Enter Password:<input type="password" name="password"><br><br>
Which of the following operation system have you used?<br>
<input type="checkbox" name="c1"> LINUX<br>
<input type="checkbox" name="c2"> WINDOWS 10<br>
<input type="checkbox" name="c3"> MACINTOSH 8.0<br>
<br>
Which of the operation system do you like<br>
<input type="radio" name="r1"> LINUX<br>
<input type="radio" name="r1"> WINDOWS 10<br>
<input type="radio" name="r1"> ACINTOSH 8.0<br>
<BR>
You have completed the form <button> Sign up </button>
</form>
</body>
</html>
<!doctype html>
<html>
<head>
<title>B2</title>
<link rel = "stylesheet" href = "b2.css">
</head>
<body>
<h3> Stylized list of elements</h3>
<ul class = "unflowering"><li>Non-Flowering Plants</li>
<ul class = "Flowering">
<li>Fern</li>
<li>Spern</li>
</ul></ul>
<ul><li class = "flowering">Flowering Plants</li>
<ul class = "flowering">
<li>Lily</li>
<li>Rose</li>
<ol class ="types">
<li>Red Rose</li>
<li>Pink Rose</li>
</ol>
</ul></ul>
</body>
</html>
<html>
<body style ="background-color:pink">
<h1 style="font-size:50; color: blue;text-align: center">
PUNE CITY</h1>
<h2 style="font-size:25; color: green">
LANDMARKS IN PUNE</h2><br>
<ol>
<li style="font-size:12; color: red"> Shaniwarvad </li>
<li style="font-size:13; color: voilet"> FC road </li>
<li style="font-size:14; color: orange"> Mg road </li>
<li style="font-size:15; color: brown"> Agarkhan palace </li>
<li style="font-size:16; color: yellow"> NIMB</li>
<ol></br><br>
<marquee style="font-size:30; color:maroon"> PUNE CITY </marquee>
<br>
<br>
<img src="/home/ty108/public_html/photo.png" width=500 height=500>
</body>
</html>
Assign 3
PHP Accept two integers(html form 2textboxes)
mod,power,sum,factorial
create form
<!doctype html>
<html>
<body >
<form method = "GET" action = "process.php">
<BR> Enter integer 1 : <input type = "number" name = "int1"> </BR>
<BR> </BR>
<BR> Enter integer 2 : <input type = "number" name = "int2"> </BR>
<BR> </BR>
</BR> <input type = "submit" value = "Submit"> </BR>
<BR> </BR>
<BR> <input type = "reset" value = "Reset"> </BR>
</form>
</body>
</html>
create process.php
<?php
$n1 = $_GET['int1'];
$n2 = $_GET['int2'];
function mod($n1,$n2)
{
return $n1%$n2;
}
function power($n1,$n2)
{
return pow($n1,$n2);
}
function sum($n1)
{
return ($n1 *($n1+1)/2);
}
function fact($n2)
{
$f = 1;
for($i = 1 ; $i <= $n2 ; $i++)
{
$f *= $i;
}
return $f;
}
echo "Mod of $n1 and $n2 :".mod($n1 , $n2);
echo "<br>";
echo "Power of $n1 raised to $n2 :".power($n1 , $n2);
echo "<br>";
echo "Sum of first $n1 numbers is ".sum($n1);
echo "<br>";
echo "Factorial of $n2 is ".fact($n2);
?>
form accept string
length,total no of vowels,lowercase,pad,remove whitespaces
reverse
FORM
<!doctype html>
<html>
<form method = "GET" action = "p1.php">
<BR> Enter a string : <input type = "text" name = "s1"> </BR>
<BR> </BR>
<input type ="radio" name = "option" value = "a"> Find length
<BR> </BR>
<input type ="radio" name = "option" value = "b"> Count vowels
<BR> </BR>
<input type ="radio" name = "option" value = "c"> Convert to lowercase then
to title case
<BR> </BR>
<input type ="radio" name = "option" value = "d"> Pad * on LHS RHS
<BR> </BR>
<input type ="radio" name = "option" value = "e"> Remove leading whitespaces
<BR> </BR>
<input type ="radio" name = "option" value = "f"> Reverse the string
</BR> <input type = "submit" value = "Submit"> </BR>
<BR> <input type = "reset" value = "Reset"> </BR>
</form>
</body>
</html>
P1.php
<?php
require "function.php";
$str = $_GET['s1'];
$option = $_GET['option'];
$l=strlen($str);
switch($option)
{
case 'a' : echo "Length of $str is ".length($str); break;
case 'b' : echo "Count of vowels in $str is ".vowel($str, $l); break;
case 'c' : echo "Case conversion of $str is ".convert($str); break;
case 'd' : echo " Padded string is ".pad($str); break;
case 'e' : echo "Removal of whitespaces ".remove($str); break;
case 'f' : echo "Reversed $str is ".reverse($str); break;
}
?>
FUNCTION
<?php
function length($str)
{
$len = 0;
for($i=0 ; $i<strlen($str) ; $i++)
{
$len++;
}
return $len;
}
function vowel($str, $l)
{
$cnt=0;
for($i=0 ; $i<$l ; $i++)
{
if(($str[$i]=='A') || ($str[$i]=='E') ||($str[$i]=='I') ||($str[$i]=='O') ||
($str[$i]=='U') ||
($str[$i]=='a') ||($str[$i]=='e') ||($str[$i]=='i') ||($str[$i]=='o') ||
($str[$i]=='u'))
$cnt++;
return $cnt;
}
function convert($str)
{
return ucwords(strtolower($str));
}
/*function pad($str)
{
return str_pad($str,2,*);
}
*/
function remove($str)
{
return trim($str," ");
}
function reverse($str)
{
return strrev($str);
}
?>
Two Strings from user
small,position,compare
FORM
<!doctype html>
<html>
<body>
<h2> String Operations </h2>
<form action="3B1.php" method="GET">
Enter the bigger string : <input type="text" name="bigstr">
<BR>
Enter the smaller string : <input type="text" name="smallstr">
</BR>
<BR> <label> Select an option </label> </BR>
<BR> <input type="radio" name="operation" value="starts">Find whether smaller
string appears at the start of large string </BR>
<BR> <input type="radio" name="operation" value="position">Find the position
of smaller string in big string </BR>
<BR> <input type="radio" name="operation" value="compare">Comparison of both
the strings </BR>
<BR> If comparing , enter the number of characters for comparing : <input
type="number" name="nchar" min="1"> </BR>
<input type="submit" value="Submit">
</form>
</body>
</html>
func3.php
<?php
function startsWith($bigStr , $smallStr)
{
return strpos($bigStr , $smallStr) === 0;
}
function findPosition($bigStr , $smallStr)
{
return strpos($bigStr , $smallStr);
}
function compareStrings($bigStr , $smallStr)
{
$bigStr = substr(strtolower($bigStr),0,$n);
$smallStr = substr(strtolower($smallStr),0,$n);
return $bigStr === $smallStr;
}
?>
<?php
require "func3.php";
if($_SERVER['REQUEST_METHOD'] == 'GET')
{
$bigString = $_GET['bigstr'];
$smallString = $_GET['smallstr'];
$operation = $_GET['operation'];
switch($operation)
{
case 'starts' : if(startsWith($bigString , $smallString))
{
echo "Small string appears at the start of big string";
}
else
{
echo "Small string does not appear at the start of the big
string";
}
break;
case 'position' : $pos = findPosition($bigString , $smallString);
if($pos === false)
{
echo "Small string does not appear in the big string";
}
else
{
echo "Small string appears at position :".$pos;
}
break;
case 'compare' : if(isset($_GET['nchar']) && $_GET['nchar']>0)
{
$n = intval($_GET['nchar']);
if(compareStrings($bigString , $smallString, $n))
{
echo "First $n characters of both the strings are equal.";
}
else
{
echo "First $n characters of both the strings are not
equal";
}
}
else
{
echo "Please provide valid no. of characters to compare";
}
break;
default : echo "Invalid operation";
}
}
?>
ASSIGN 4
array 30 temperatures
<?php
$temps=[18,20,22,19,23,25,24,26,27,21,19,18,20,23,24,28,29,26,25,24,22,21,20,27,26,
28,25,22,23,24];
$avg_temp=array_sum($temps)/count($temps);
sort($temps);
$coolest_temp = array_slice($temps,0,5);
$warmest_temp = array_slice($temps,-5);
?>
<!DOCTYPE html>
<html>
<head>
<title>Weather Summary</title>
</head>
<body>
<h2>Weather Summary for the spring month</h2>
<p>Average High Temprature:
<?php
echo number_format($avg_temp,2);
?>
°C
</p>
<p>Five Coolest High Tempratures:
<?php echo implode("°C, ",$coolest_temp);
?>
°c</p>
<p>Five Warmest High Temprature:
<?php echo implode("°C, ",$warmest_temp);
?>
°C
</p>
</body>
</html>
menu driven arraypush pop shift
insert,delete,display,stack &queue
<html>
<body>
<form action ="Array.php" method="POST">
<p> Choose an operation : </p>
Enter the element you want to insert : <input type="number" name="num"> <br>
<input type="radio" name="operation" value="insert"> Insert an element in the
stack <BR>
<input type="radio" name="operation" value="delete"> Delete an element from
stack <BR>
<input type="radio" name="operation" value="display"> Display contents of
stack <BR>
<input type="radio" name="operation" value="insert_q"> Insert an element in
the queue <BR>
<input type="radio" name="operation" value="delete_q"> Delete an element from
queue <BR>
<input type="radio" name="operation" value="display_q"> Display contents of
queue <BR>
<input type="Submit" value="Perform Operation">
</form>
</body>
</html>
Array.php
<?php
$stack = array(1,2,3,4);
$queue = array(11,12,13,14);
if($_SERVER["REQUEST_METHOD"]=="POST")
{
$operation = $_POST["operation"];
$num = $_POST["num"];
switch($operation)
{
case "insert" : array_push($stack, $num);
echo "$num inserted in stack";
print_r($stack);
break;
case "delete" : if(empty($stack))
{
echo "Stack is empty";
}
else
{
$deleted = array_pop($stack);
echo "$deleted deleted from stack";
}
break;
case "display" : echo "Stack contents :";
print_r($stack);
break;
case "insert_q" : array_push($queue, $num);
echo "$num inserted in queue";
print_r($queue);
break;
case "delete_q" : if(empty($queue))
{
echo "Queue is empty";
}
else
{
$deleted = array_shift($queue);
echo "$deleted deleted from queue";
}
break;
case "display_q" : echo "Queue contents :";
print_r($queue);
break;
}
}
?>
QB1. php script inserts a new item in array at any pos
<?php
function insertItem(&$array, $item, $position) {
array_splice($array, $position, 0, $item);
}
$myArray = [1,2,3,4,5,6,7];
$newItem = 50;
$position = 3;
insertItem($myArray, $newItem, $position);
print_r($myArray);
?>