15CSL77 - Web Lab Manual - 19-20 PDF
15CSL77 - Web Lab Manual - 19-20 PDF
15CSL77 - Web Lab Manual - 19-20 PDF
:
NAME OF THE STUDENT
BATCH :
15CSL77-Web Technology Lab manual
To create an ambience in excellence and provide innovative emerging programs in Computer Science
and Engineering and to bring out future ready engineers equipped with technical expertise and strong
ethical values.
2. Quality Research: To provide strong theoretical and practical background across the
Computer Science and Engineering discipline with the emphasis on computing technologies,
quality research, consultancy and trainings.
PEO1: Current Industry Practices: Graduates will analyze real world problems and give
solution using current industry practices in computing technology.
PEO2: Research & Higher Studies: Graduates with strong foundation in mathematics and
engineering fundamentals that will enable graduates to pursue higher
learning ,R&D activities and consultancy.
PEO3: Social Responsibility: Graduates will be professionals with ethics, who will provide
industry growth and social transformation as responsible citizens.
PROGRAM OUTCOMES
2. Problem analysis: Identify, formulate, research literature, and analyze complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural sciences,
and engineering sciences.
3. Design / development of solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for the
public health and safety, and the cultural, societal, and environmental considerations.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with an
understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the
professional engineering practice.
7. Environment and sustainability: Understand the impact of the professional engineering solutions
in societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of
the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.
11. Project management and finance: Demonstrate knowledge and understanding of the engineering
and management principles and apply these to one’s own work, as a member and leader in a team, to
manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
PSO1: Programming: Ability to understand, analyze and develop computer programs in the areas
related to algorithms, system software, multimedia, web design, DBMS, and networking for efficient
design of computer-based systems of varying complexity.
PSO2:Practical Solution: Ability to practically provide solutions for real world problems with a
broad range of programming language and open source platforms in various computing domains.
PSO3:Research: Ability to use innovative ideas to do research in various domains to solve societal
problems.
COURSE OBJECTIVES:
Design and develop static and dynamic web pages.
Develop a web application project using HTML, JavaScript, XML, CSS and PHP with a good look and
feel effects.
Design the layouts and understand the requirements for web page creation.
Familiarize with client side program, server-side programming and active server pages.
Learn Database Connectivity to web applications
PREREQUISITES:
Basic knowledge about computer programming
COURSE OUTCOMES (CO’s):
Course Course Outcome
Code
Design and develop dynamic web pages with good aesthetic sense of
C407.1
designing and latest technical know-how's.
Design, develop and implement web applications based on Javascript, HTML5,
C407.2
XML,CSS and PHP .
C407.3 Gain the creativity and imagination to build the web pages
Have a good understanding of Web Application Terminologies, Internet Tools
C407.4 other web services
C407.5 Learn how to link and publish web sites
Course objectives:
• The course will give you a grounding in the nuts and bolts of the tags, script, and code that create
web
pages.
• Learning how the web and web pages work by building on the skills and to understand the potentials
on writing for web pages.
• Design, develop and implement web applications based on Javascript, HTML5, XML,CSS and PHP .
• Develop a web application project using HTML,JavaScript,XML,CSS and PHP with a good look and
feel effects.
• Design the project using web development framework along with essential database connectivity.
Lab Experiments
Part A: WEB TECHNOLOGY PRACTICALS
Sl.No. Program RBTL CO
CO
1 Write a javascript to design a simple calculator to perform the following operations: L3 1,2,3,4,5
sum, product, difference and quotient.
CO
Write a JavaScript that calculates the squares and cubes of the numbers from 0 to 10 and L3 1,2,3,4,5
2 outputs HTML text that displays the resulting values in an HTML table format.
CO
Write a JavaScript code that displays text “TEXT-GROWING” with increasing font size in L3 1,2,3,4,5
3 the interval of 100ms in RED COLOR, when the font size reaches 50pt it displays “TEXT-
SHRINKING” in BLUE color. Then the font size decreases to 5pt
L3 CO
Develop and demonstrate a HTML5 file that includes JavaScript script that uses functions 1,2,3,4,5
for the following problems: a. Parameter: A string
4 b. Output: The position in the string of the left-most vowel
c. Parameter: A number
d. Output: The number with its digits in the reverse order
CO
Design an XML document to store information about a student in an engineering college L3 1,2,3,4,5
5 affiliated to VTU. The information must include USN, Name, and Name of the College,
Branch, Year of Joining, and email id. Make up sample data for 3 students. Create a CSS
style sheet and use it to display the document.
CO
6 Write a PHP program to keep track of the number of visitors visiting the web page and to L3 1,2,3,4,5
display this count of visitors, with proper headings.
CO
7 Write a PHP program to display a digital clock which displays the current time of the L3 1,2,3,4,5
server. CO
8 Write the PHP programs to do the following: a. Implement simple calculator operations. b. L3 1,2,3,4,5
Find the transpose of a matrix. c. Multiplication of two matrices. d. Addition of two
matrices
CO
Write a PHP program named states.py that declares a variable states with value L3 1,2,3,4,5
"Mississippi Alabama Texas Massachusetts Kansas". write a PHP program that does the
following:
9 a. Search for a word in variable states that ends in xas. Store this word in element 0 of a list
named states List.
b. Search for a word in states that begins with k and ends in s. Perform a case insensitive
comparison. [Note: Passing re.Ias a second parameter to method compile performs a case-
insensitive comparison.] Store this word in element1 of states List.
c. Search for a word in states that begins with M and ends in s. Store this word in element 2
of the list.
CO
10 Write a PHP program to sort the student records which are stored in the database using L3 1,2,3,4,5
selection sort.
C407.1 3 3 2 2 - - - - - - - - 3 3 1
C407.2 3 3 2 2 - - - - - - - - 3 3 1
C407.3 3 3 3 2 - - - - - - - - 3 3 1
C407.4 3 3 2 2 - - - - - - - - 3 3 1
C407.5 3 3 3 2 - - - - - - - - 3 3 1
Average 3 3 3 2 - - 3 3 1
INSTRUCTIONS
1. The exercises are to be solved in an editor like Notepad++, dreamViewer.
2. Front end may be created using either HTML5 or HTML or any other framework.
4. The student need not create the front end in the examination. The results of the program may be
displayed directly.
5. Modification of existing program also be asked in the examination.
6. Questions must be asked based on lots.
PROGRAM:
<style type="text/css">
body
{
background-color: #CCCCFF;
margin: 30px;
}
#result
{
display: block;
border: solid thin black;
padding: 5px;
}
</style>
function getNum()
{
num1 = document.getElementById("firstNumber").value;
num2 = document.getElementById("secondNumber").value;
if(isNaN(num1) ||isNaN(num2) )
document.getElementById("result").innerHTML = "Enter valid Number";
}
function add()
{
getNum();
document.getElementById("result").innerHTML = +num1 + +num2;
}
function multiply()
{
getNum();
document.getElementById("result").innerHTML = num1 * num2;
}
function divide()
{
getNum();
document.getElementById("result").innerHTML = num1 / num2;
}
function quotient()
{
getNum();
document.getElementById("result").innerHTML = Math.trunc(num1 / num2);
}
</script>
</head>
<body>
<h3> Simple Javascript Calculator</h3>
<form>
<p> 1st Number : <input type="text" id="firstNumber" /> </p>
<p> 2nd Number: <input type="text" id="secondNumber" /> </p>
<input type="button" onClick="add()" Value="Add" />
<input type="button" onClick="multiply()" Value="Multiply" />
<input type="button" onClick="divide()" Value="Divide" />
<input type="button" onClick="quotient()" Value="Quotient" />
</form>
</body>
</html>
Output:
Viva Questions:
1. What is HTML?
HTML, or HyperText Markup Language, is a Universal language which allows an individual using
special code to create web pages to be viewed on the Internet.
3. What is a tag?
In HTML, a tag tells the browser what to do. When we write an HTML page, we enter tags for many
reasons -- to change the appearance of text, to show a graphic, or to make a link to another page.
The selector points to the HTML element you want to style. The declaration block contains one or
more declarations separated by semicolons. Each declaration includes a CSS property name and a
value, separated by a colon.
CSS selectors are used to "find" (or select) HTML elements based on their element name, id, class,
attribute, and more.
The element selector selects elements based on the element name.You can select all <p> elements on a
page like this (in this case, all <p> elements will be center-aligned, with a red text color):
Example
p{
text-align: center;
color: red;
}
The id Selector
The id selector uses the id attribute of an HTML element to select a specific element. The id of an
element should be unique within a page, so the id selector is used to select one unique element!
To select an element with a specific id, write a hash (#) character, followed by the id of the element.
The style rule below will be applied to the HTML element with id="para1":
Example
#para1 {
text-align: center;
color: red;
}
The class selector selects elements with a specific class attribute.To select elements with a specific
class, write a period (.) character, followed by the name of the class. In the example below, all HTML
elements with class="center" will be red and center-aligned:
Example
.center {
text-align: center;
color: red;
}
6. Explain JavaScript HTML DOM Elements
HTML Elements can be handled by the following ways:
Technically, since HTML is an SGML application, HTML uses SGML comment syntax. However,
the full syntax is complex, and browsers don't support it in its entirety anyway. Therefore, use the
following simplified rule to create HTML comments that both have valid syntax and work in browsers:
An HTML comment begins with "<!--", ends with "-->", and does not contain "--" or ">" anywhere in
the comment.
The following are examples of HTML comments:
* <!-- This is a comment. -->
* <!-- This is another comment,
and it continues onto a second line. -->
* <!---->
8. What is <!DOCTYPE> ?
The <!DOCTYPE> declaration must be the very first thing in your HTML document, before the
<html> tag.
The <!DOCTYPE> declaration is not an HTML tag; it is an instruction to the web browser about what
version of HTML the page is written in.
2. Write a JavaScript that calculates the square and cubes of the numbers from 0 to
10 and outputs HTML text that displays the resulting values in an HTML table
format.
PROGRAM:
<!DOCTYPE html>
<head>
<meta charset=utf-8 />
<title> Javascript program to display squares and cubes</title>
<style type="text/css">
body
{
background-color: #CCFFCC;
color:green;
margin: 30px;
}
table,th,td
{
border:1px solid black;
border-collapse:collapse;
padding: 5px;
}
</style>
</head>
<body>
<h3> Squares and Cubes of Numbers 0 to 10</h3>
<table> <tr> <th>Number</th> <th>Square</th> <th>Cube</th> </tr>
<script type="text/javascript">
for(var n=0; n<=10; n++)
{
2. What is JavaScript ?
Javascript is a dynamic computer programming language. It is lightweight and most commonly used
as a part of web pages, whose implementations allow client-side script to interact with the user and
make dynamic pages.
We can insert JavaScript in HTML using <Script tag>. JavaScript can be enclosed in <script type =
text/javascript> and ending with </script>.
Example:
<html>
<body>
<script type="text/javascript">
...JavaScript….
</script>
</body>
</html>
function function_name()
{
//function body
}
<!DOCTYPE html>
<head>
<meta charset=utf-8 />
<title> Javascript program to grow and shrink text</title>
<style type="text/css">
body
{
background-color: #CCFFCC;
color:green;
margin: 30px;
}
</style>
<script type="text/javascript">
if(fs>50)
{
clearInterval(anim);
anim = setInterval(shrink,100);
}
}
function shrink()
{
fs-=5;
document.getElementById("animText").innerHTML="TEXT-SHRINKING";
document.getElementById("animText").style.color="blue";
document.getElementById("animText").style.fontSize=fs+"pt";
if(fs<5)
{
clearInterval(anim);
anim = setInterval(grow,100);
}
}
</script>
</head>
<body>
<p>
<span id ="animText"></span>
</p>
</body>
</html>
Output:
Viva Questions:
1. What is CSS?
CSS stands for Cascading Style Sheets. By using CSS with HTML we can change the look of the web
page by changing the font size and color of the font. CSS plays an important role in building the
website. Well written CSS file can be used to change the presentation of each web page. By including
only one CSS file. It gives web site developer and user more control over the web pages.
4. Develop and demonstrate a HTML5 file that includes JavaScript script that uses
functions for the following problems:
a. Parameter: A string
b. Output: The position in the string of the left-most vowel
c. Parameter: A number
d. Output: The number with its digits in the reverse order
PROGRAM:
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Javascript functions </title>
<style type="text/css">
body
{
background-color: #FFFDD0;
color:#8C8833;
margin: 30px;
}
#resultS, #resultN
{
display: block;
background-color: #FFFFFF;
}
#warningN
{
color:red;
font-style:italic;
}
</style>
function lvowel()
{
var str = document.getElementById("paramS").value.toUpperCase();
for(var i=0; i<str.length; i++)
{
chr = str.charAt(i);
if(chr=='A' || chr=='E' || chr=='I' || chr == 'O' || chr=='U')
{
document.getElementById("resultS").innerHTML="The leftmost vowel is in
position "+(i+1);
break;
}
}
}
function rev()
{
var num = document.getElementById("paramN").value;
if(isNaN(num))
{
document.getElementById("warningN").innerHTML = "Enter a valid Number!";
return;
}
else
document.getElementById("warningN").innerHTML = "";
var rev="";
</script>
</head>
<body>
<header>
<h1>Javascript functions</h1>
</header>
<nav>
<ul>
<li>Find Left Most Vowel</li>
<li>Reverese of Number</li>
</ul>
</nav>
<section>
<h2 id="option">Choose an option</h2>
<article>
<h3> Find the left most vowel </h3>
<p>
</article>
<article>
<h3> Find the reverse of a number </h3>
<p>
Enter a number: <input id ='paramN' type='text' size='10' /> <span id="warningN"></span> <br />
<button onClick='rev()'> Enter </button>
</p>
<p id="resultN"> </p>
</article>
</section>
<footer>
<p>© 2019 MVJCE. All rights reserved.</p>
</footer>
</body>
</html>
Output:
Example:
<p>
<span style="color:#000000;">
In this page we use span.
</span>
</p>
Display as:
1. First item
2. Second item.
Inside a <button> element you can put content, like text or images. This is the difference between this
element and buttons created with the <input> element.
1. studentDetails.xml
<STUDENT>
<USN>1MJ11CS001</USN>
<NAME>Arun Kumar</NAME>
<COLLEGE>MVJ College of Engineering</COLLEGE>
<BRANCH>Computer Science and Engineering</BRANCH>
<YEAR>2011</YEAR>
<EMAILID>[email protected]</EMAILID>
</STUDENT>
<STUDENT>
<USN>1MJ10ME012</USN>
<NAME>Swaroop J</NAME>
<COLLEGE>MVJ College of Engineering</COLLEGE>
<BRANCH>Mechanical Engineering</BRANCH>
<YEAR>2010</YEAR>
<EMAILID>[email protected]</EMAILID>
</STUDENT>
<STUDENT>
<USN>1MJ12AE030</USN>
<NAME>Pradeep L</NAME>
<COLLEGE>MVJ College of Engineering</COLLEGE>
<BRANCH>Aeronautical Engineering</BRANCH>
<YEAR>2012</YEAR>
<EMAILID>[email protected]</EMAILID>
</STUDENT>
</VTU>
2. student.css
VTU
{
background-color: #ffFFff;
width: 100%;
}
STUDENT
{
display: block;
margin-bottom: 30pt;
margin-left: 0;
}
USN,NAME
{
color: #FF9900;
font-size: 14pt;
}
COLLEGE,BRANCH,YEAR
{
display: block;
color: #000000;
margin-left: 20pt;
}
EMAILID
{
display: block;
color: #0000FF;
margin-left: 20pt;
font-style: italic;
}
Output:
Viva Questions:
1. What is XML?
XML is no way clashes with HTML, since they are for two different purposes.
HTML XML
HTML is used to mark up text so it can be XML is used to mark up data so it can be
displayed to users. processed by computers.
HTML describes both structure (e.g. <p>, XML describes only content, or “meaning”
HTML uses a fixed, unchangeable set of tags In XML, you make up your own tags
CSS Padding
The CSS padding properties are used to generate space around an element's content, inside of any
defined borders.
With CSS, you have full control over the padding. There are properties for setting the padding for each
side of an element (top, right, bottom, and left).
6. Write a PHP program to keep track of the number of visitors visiting the web
page and to display this count of visitors, with proper headings.
PROGRAM:
<style type="text/css">
body
{
background-color: #FFF6FF;
color:#D690D9;
margin: 30px;
}
.visitor
{
color: blue
}
</style>
</head>
<body>
<?php
$handle = fopen("counter.txt", "r");
if(!$handle)
{
Output:
Note : you can put any sample content. Design a page to showcase your hobbies/interests and put a
visitor counter php script at the end.
1. What is PHP?
PHP is a recursive acronym for "PHP: Hypertext Preprocessor". PHP is a server side scripting
language that is embedded in HTML. It is used to manage dynamic content, databases, session
tracking, even build entire e-commerce sites.
echo in PHP
• echo is language constructs that display strings.
• echo has a void return type.
• echo can take multiple parameters separated by comma.
• echo is slightly faster than print.
Print in PHP
• print is language constructs that display strings.
• print has a return value of 1 so it can be used in expressions.
• print cannot take multiple parameters.
• print is slower than echo. How will you redirect a page using PHP?
5. What is header() ?
The PHP header() function supplies raw HTTP headers to the browser and can be used to redirect it to
another location. The redirection script should be at the very top of the page to prevent any other part
of the page from loading. The target is specified by the Location: header as the argument to the
header() function. After calling this function the exit() function can be used to halt parsing of rest of
the code.
Once a file is opened using fopen() function it can be read with a function called fread(). This function
requires two arguments. These must be the file pointer and the length of the file expressed in bytes.
<?php
$filename = "tmp.txt";
$file = fopen( $filename, "r" );
7. Write a PHP program to display a digital clock which displays the current time
of the server.
PROGRAM:
body
{
background-color: #800020;
color:#6DF3D1;
margin: 30px;
}
#clock
{
margin: 20px;
padding: 20px;
width:400px;
border: medium dotted pink;
font-size: 50pt;
font-family : Century Gothic,sans-serif
}
</style>
</head>
<body>
<hr />
<?php
date_default_timezone_set('Asia/Kolkata');
$page = $_SERVER['PHP_SELF'];
$sec = "1";
header("Refresh: $sec; url=$page");
?>
<div id="clock"><?php echo idate("H") . " : ". idate("i"). " : ". idate("s");
usleep (100);?> </div>
</body>
</html>
Output:
1. How will you get current date and time using PHP?
PHP's time() function gives you all the information that you need about the current date and time. It
requires no arguments but returns an integer.
Eg:
<?php
$date_array = getdate();
print $formated_date;
?>
2. How will you access session variables in pHP?
Session variables are stored in associative array called $_SESSION[]. These variables can be accessed
during lifetime of a session.
One of the environment variables set by PHP is HTTP_USER_AGENT which identifies the user's
browser and operating system.
PROGRAM:
1. phpcalcMatrix.php
body
{
background-color: #FFF8DA;
color:#806E21;
margin: 30px;
}
#calculator
{
margin: 20px;
padding: 20px;
float: center;
border: thin solid black;
}
</style>
</head>
<body>
<h1> PHP Simple Calculator, Matrix operations</h1>
<div id ="calculator">
<h3> Simple Calculator</h3>
<form method = "get" action ="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="num1" placeholder="Number 1" />
<input type="text" name="num2" placeholder="Number 2" />
<select name="operator">
<option></option>
<?php
if(isset($_GET['submit']))
{
$n1= $_GET['num1']; $n2 = $_GET['num2'];
$op = $_GET["operator"];
if(is_numeric($n1) && is_numeric($n2) )
{
$result = eval("return $n1 $op $n2;");
}
else
$result = "undefined";
//Note : eval is a dangerous function to use, so input has to be verified
/*switch($op){
case "+":
$result = $n1+$n2;
break;
case "-":
$result = $n1+$n2;
break;
case "*":
$result = $n1*$n2;
break;
case "/";
$result = $n1/$n2;
break;
}
*/
echo "<p> The result is : $result</p>";
}
?>
</div>
<div>
<h2> Matrix Operations</h2>
<ul>
<li> <a href="matTranspose.php">Transpose of a matrixx</a></li>
<li> <a href="matAM.php?op=mult">Multiply 2 Matrices</a></li>
</ul>
</div>
</body>
</html>
2. matTranspose.php
body
{
background-color: #FFF8DA;
color:#806E21;
margin: 30px;
}
#matrix
{
margin: 20px;
padding: 20px;
float: center;
border: thin solid black;
}
</style>
</head>
<body>
<a href="phpcalcMatrix.php">Back to Main Menu</a>
<h2>Transpose of a Matrix</h2>
<div id="matrix">
<form method="get" action = "matTranspose.php" >
Enter m an n values for m x n matrix :
<input type = "text" name ="m" size="5" placeholder="m" /> <input type = "text" name ="n"
size="5" placeholder="n" />
<input type = "submit" name="genMatrix" value="Enter" />
</form>
<?php
if(isset($_GET["genMatrix"]))
{
$m = $_GET['m']; $n = $_GET['n'];
echo "<form method= 'get' action = 'matTranspose.php'><table>";
for($i=0; $i<$m; $i++)
{
echo "<tr>";
for($j=0; $j<$n; $j++)
{
$val =$i.":".$j;
echo "<td><input type='text' size='4' name=$val /></td>";
}
echo"</tr>";
}
echo "</table>";
echo "<input type='hidden' name= 'm' value=$m /><input type='hidden' name='n' value=$n />";
echo "<input type='submit' name='transpose' value='Find Transpose' />";
echo "</form>";
}
if(isset($_GET["transpose"]))
{
$m = $_GET['m']; $n = $_GET['n'];
echo "Matrix Entered <br />";
for($i=0; $i<$m; $i++)
{
for($j=0; $j<$n; $j++)
{
$val =$i.":".$j;
$mat[$i][$j] = $_GET["$val"]; $transpose[$j][$i] = $mat[$i][$j];
echo $mat[$i][$j]." ";
}
echo "<br />";
}
echo "<p>Transpose of the Matrix : <br />";
for($i=0;$i<$n;$i++)
{
for($j=0;$j<$m;$j++)
{
echo $transpose[$i][$j]." ";
}
echo "<br />";
}
echo "</p>";
}
?>
</div>
</body>
</html>
3. matAM.php
body
{
background-color: #FFF8DA;
color:#806E21;
margin: 30px;
}
table,tr,th,td
{
border-collapse:collapse;
border: thin solid black;
padding:20px
}
.warning
{
color:red;
font-style: italic
}
</style>
</head>
<body>
<div>
if(isset($_GET["genMatrix"]))
{
$m1 = $_GET['m1']; $n1 = $_GET['n1'];
$m2 = $_GET['m2']; $n2 = $_GET['n2'];
echo "<div>";
echo "<h4> Matrix 1 </h4>";
echo "<input type='hidden' name= 'm1' value=$m1 /><input type='hidden' name='n1' value=$n1 />";
echo "<input type='hidden' name= 'm2' value=$m2 /><input type='hidden' name='n2' value=$n2 />";
echo "<input type='hidden' name = 'op' value='$op' />";
echo "<input type='submit' name='submit' value='Enter' />";
echo "</form>";
} // end else
}
if(isset($_GET["submit"]))
{
{
$val ="M2:".$i.":".$j;
$mat2[$i][$j] = $_GET["$val"];
echo $mat2[$i][$j]." ";
}
echo "<br />";
}
echo "</td><td>";
if($op =="mult")
{
for($i=0;$i<$m1;$i++)
{
for($j=0;$j<$n2;$j++)
{
$mul[$i][$j]=0;
for($k=0;$k<$m2;$k++)
{
$mul[$i][$j]+=$mat1[$i][$k] *$mat2[$k][$j];
}
echo $mul[$i][$j]." ";
}
echo "<br />";
}
}
echo "</td></tr></table>";
}
?>
</div>
</body>
</html>
OUTPUT:
Multiply 2 Matrices
Add 2 Matrices
1. Explain how array can be created & elements are accessed in php?
An array is a data structure that stores one or more similar type of values in a single value.
There are three different kind of arrays and each array value is accessed using an ID c which is called
array index.
• Numeric array − An array with a numeric index. Values are stored and accessed in
linear fashion.
• Associative array − An array with strings as index. This stores element values in
association with key values rather than in a strict linear index order.
• Multidimensional array − An array containing one or more arrays and values are
accessed using multiple indices
<?php
/* Method to create Numeric array. */
$numbers = array( 1, 2, 3, 4, 5);
The PHP default variable $_PHP_SELF is used for the PHP script name and when you click "submit"
button then same PHP script will be called.
9. Write a PHP program named states.py that declares a variable states with value
"Mississippi Alabama Texas Massachusetts Kansas". Write a PHP program that
does the following:
a). Search for a word in variable states that ends in xas.
Store this word in element 0 of a list named statesList.
b). Search for a word in states that begins with k and ends in s. Perform a
case-insensitive comparison.
[Note: Passing re.Ias a second parameter to method compile performs a
case-insensitive comparison.]
Store this word in element1 of statesList.
c). Search for a word in states that begins with M and ends in s. Store this
word in element 2 of the list.
d). Search for a word in states that ends in a. Store this word in element 3 of
the list.
PROGRAM:
1. states.php
<?php
?>
2. search.php
body
{
background-color: #F0F8FF;
color:#456B8C;
margin: 30px;
}
#calculator
{
margin: 20px;
padding: 20px;
float: center;
border: thin solid black;
}
</style>
</head>
<body>
preg_match('/\b(k\w*s)\b/i', $states,$match);
$statesList[1] = $match[0];
preg_match('/\b(M\w*s)\b/', $states,$match);
$statesList[2] = $match[0];
preg_match('/\b(\w*a)\b/', $states,$match);
$statesList[3] = $match[0];
echo "<h4> State beginning with k and ending in s -case insensitive </h4>";
echo $b;
?>
</body>
</html>
Output:
Viva Questions:
1. How do you get information from a form that is submitted using the "get" method?
$_[GET]
2. How will you get information sent via GET & POST method?
The PHP provides $_GET associative array to access all the sent information using GET method.
The PHP provides $_POST associative array to access all the sent information using POST method.
The strpos() function is used to search for a string or character within a string. If a match is found in
the string, this function will return the position of the first match. If no match is found, it will return
FALSE. Let's see if we can find the string "world" in our string −
<?php
echo strpos("Hello world!","world");
?>
10. Write a PHP program to sort the student records which are stored in the
database using selection sort.
PROGRAM:
Go to http://localhost/phpmyadmin/
Type “student_db” under Create database and click “Create”
Type “student_tbl” and give number of fields as 5 under “Create New Table” and click
“Create”
Specify names of fields, ID, USN, Name, branch, batch with appropriate data types. Add more
fields if required, click “Save”.
Click on the key button in the ID row and make it Primary Key
Edit ID field and set it to AutoIncrement.
Enter 5 rows by clicking on insert and using GUI or selecting SQL and writing SQL statements
(Leave ID field empty, it will be auto-incremented)
Click on “Browse” to see all the rows
<head >
<style type="text/css">
</style>
</head>
<body>
<?php
/* Sort USN wise assuming batch and branch are the same */
$results_con = mysqli_connect("localhost","root","","student_db");
if (mysqli_connect_errno())
if($result = $results_con->query($query)) {
echo "<table><tr><th></th><th>USN</th><th><Name</th><th>Branch</th><th>Batch</th></tr>";
while($row= $result->fetch_assoc()) {
echo "<tr><td>".$row["ID"]."</td>";
echo "<td>".$row["USN"]."</td>";
echo "<td>".$row["Name"]."</td>";
echo "<td>".$row["Branch"]."</td>";
echo "<td>".$row["batch"]."</td></tr>";
echo "</table>";
$result = $results_con->query($query);
$rowcount =mysqli_num_rows($result);
$i=0; $j=0;
while($row = $result->fetch_array()) {
while($urow = $result->fetch_array()) {
if (strnatcmp($urow[1],$minUSN)<0){
$result_min = $results_con->query($query_min);
$min_rec = $result_min->fetch_array();
$result_swap = $results_con->query($query_swap);
$result_swap = $results_con->query($query_swap2);
$i++;
if($i==$rowcount-1) break;
$result = $results_con->query($query);
mysqli_data_seek($result,$i);
if($result = $results_con->query($query)) {
echo "<table><tr><th></th><th>USN</th><th><Name</th><th>Branch</th><th>Batch</th></tr>";
while($row= $result->fetch_assoc()) {
echo "<tr><td>".$row["ID"]."</td>";
echo "<td>".$row["USN"]."</td>";
echo "<td>".$row["Name"]."</td>";
echo "<td>".$row["Branch"]."</td>";
echo "<td>".$row["batch"]."</td></tr>";
echo "</table>";
?>
</body>
</html>
Output:
Viva Questions:
1. How can we find the number of rows in a result set using PHP?
2. How can we know the number of days between two given dates using PHP?
<html>
<head>
<title>Event!!!</title>
<script type="text/javascript">
function trigger()
{
document.getElementById("hover").addEventListener("mouseover", popup);
function popup()
{
alert("Welcome to my WebPage!!!");
}
}
</script>
<style>
p
{
font-size:50px;
position: fixed;
left: 550px;
top: 300px;
}
</style>
</head>
<body onload="trigger();">
<p id="hover">Welcome!!!</p>
</body>
</html>
<html>
<head>
<style type="text/css">
body * {
margin: 10px;
border: 1px solid blue;
}
</style>
</head>
<body>
<form onclick="alert('form')">FORM
<div onclick="alert('div')">DIV
<p onclick="alert('p')">P</p>
</div>
</form>
</body>
</html>
3)PHP function to test whether a number is greater than 30, 20 or 10 using ternary operator.
<?php
function trinary_Test($n){
$r = $n > 30
? "greater than 30"
: ($n > 20
? "greater than 20"
: ($n >10
? "greater than 10"
: "Input a number atleast greater than 10!"));
<?php
for( $i=65; $i<=69; $i++){
for($j=5; $j>=$i-64; $j--){
echo chr($i);
}
echo "<br>";
}
?>
<html>
<body>
<form method="post">
Enter a number:
<input type="number" name="number">
<input type="submit" value="Submit">
</form>
</body>
</html>
<?php
if($_POST){
$number = $_POST['number'];
//divide entered number by 2
//if the reminder is 0 then the number is even otherwise the number is odd
if(($number % 2) == 0)
{
echo "$number is an Even number";
}
else
{
echo "$number is Odd number";
}
}
?>
Output:
PART- B:MINI-PROJECT
Student should develop mini project on the topics mentioned below or similar applications using Open GL API.
Consider all types of attributes like color, thickness, styles, font, background, speed etc., while doing mini
project. (During the practical exam: the students should demonstrate and answer Viva-Voce)
Do’s
1. Do wear ID card and follow dress code.
2. Do log off the computers when you finish.
3. Do ask the staff for assistance if you need help.
4. Do keep your voice low when speaking to others in the LAB.
5. Do ask for assistance in downloading any software.
6. Do make suggestions as to how we can improve the LAB.
7. In case of any hardware related problem, ask LAB in charge for solution.
8. If you are the last one leaving the LAB , make sure that the staff in charge of the LAB is
informed to close the LAB.
9. Be on time to LAB sessions.
10. Do keep the LAB as clean as possible.
Don’ts
1. Do not use mobile phone inside the lab.
2. Don’t do anything that can make the LAB dirty (like eating, throwing waste papers etc).
3. Do not carry any external devices without permission.
4. Don’t move the chairs of the LAB.
5. Don’t interchange any part of one computer with another.
6. Don’t leave the computers of the LAB turned on while leaving the LAB.
7. Do not install or download any software or modify or delete any system files on any lab
computers.
8. Do not damage, remove, or disconnect any labels, parts, cables, or equipment.
9. Don’t attempt to bypass the computer security system.
10. Do not read or modify other user’s file.
11. If you leave the lab, do not leave your personal belongings unattended. We are not responsible
for any theft.