Module 1 Lecture 3
Module 1 Lecture 3
1
AIIT - L
2
AIIT - L
HTML is heavily used for creating pages that are displayed on the world
wide web. Every page contains a set of HTML tags, including hyperlinks
which are used for connecting to other pages. Every page that we witness
on the world wide web is written using a version of HTML code
3
AIIT - L
Block-level Elements
<p>The DIV element is a block element, and will always start on a new line and take
up the full width available (stretches out to the left and right as far as it can).</p>
</body>
</html>
4
AIIT - L
Hello World
The DIV element is a block element, and will always start on a new line and
take up the full width available
5
AIIT - L
Inline Elements
<p>The SPAN element is an inline element, and will not start on a new line and
only takes up as much width as necessary.</p>
</body>
</html>
6
AIIT - L
7
AIIT - L
<B>, <STRONG>
<I><U>
<HR>
Example
Align a <hr> element (with CSS):
<hr style="width:50%;text-align:left;margin-left:0">
<hr style="height:60px">
<P>
<SUB>
<SUP> 8
AIIT - L
<OL>
<LI>
</OL>
<UL>
<LI>
</UL>
9
AIIT - L
Exercise:
10
AIIT - L
11
AIIT - L
•<input type="button">
•<input type="checkbox">
•<input type="color">
•<input type="date">
•<input type="email">
•<input type="file">
•<input type="hidden">
12
AIIT - L
<input type="image">
•<input type="month">
•<input type="number">
•<input type="password">
•<input type="radio">
•<input type="range">
•<input type="reset">
•<input type="submit">
•<input type="tel">
•<input type="text"> (default value)
•<input type="time">
•<input type="url">
•<input type="week">
13
AIIT - L
14
AIIT - L
SELECT TAG
15
AIIT - L
TEXTAREA TAG
</textarea>
16
AIIT - L
autofocus
Specifies that a text area should automatically get focus when the
page loads
17
AIIT - L
18
AIIT - L
19
AIIT - L
20
AIIT - L
21
AIIT - L
22
AIIT - L
23
AIIT - L
24
AIIT - L
25
AIIT - L
26
AIIT - L
HTML>
<head>
<title>frames
</title>
</head>
<BODY>
<TABLE BORDER=6>
<TR><TD> <A HREF="https://www.INDIATVNEWS.COM"
TARGET="LEFTBOTTOM"> INDIA-TV </A>      
</BODY>
</HTML>
27
AIIT - L
<BODY>
<CENTER>
YOU ARE WELCOME
</CENTER>
</BODY>
28
AIIT - L
29
AIIT - L
30
AIIT - L
<HTML>
<
<HEAD>
<TITLE> TABLES </TITLE>
</HEAD>
<BODY>
<CENTER>
<H1> <U>TIME TABLE OF BCA -VI </U> </H1>
31
AIIT - L
<TR> <TH>DAYS/TIMINGS<TH>9.15-10.10<TH>10.15-11.10<TH>11.15-12.10<TH>12.15-
1.10 <TH>1.15-2.10<TH>2.15-3.10<TH>3.15-4.10<TH>4.15-5.10
<TR ALIGN="CENTER"><TH>TUE<TD>LECTURE-1<TD>LECTURE-2<TD>LECTURE-
3<TD>LECTURE-4<TD>LECTURE-5<TD>LECTURE-6<TD>LECTURE-7
<TR ALIGN="CENTER"><TH>WED<TD>LECTURE-1<TD>LECTURE-2<TD>LECTURE-
3<TD>LECTURE-4<TD>LECTURE-5<TD COLSPAN=2>ENGLISH
<TR ALIGN="CENTER"><TH>THU<TD>LECTURE-1<TD>LECTURE-2<TD>LECTURE-
3<TD>LECTURE-4<TD>LECTURE-5<TD>LECTURE-6<TD>LECTURE-7
<TR ALIGN="CENTER"><TH>FRI<TD>LECTURE-1<TD>LECTURE-2<TD>LECTURE-
3<TD>LECTURE-4<TD>LECTURE-5<TD>LECTURE-6<TD>LECTURE-7
32
</TABLE>
AIIT - L
<
</CENTER>
</BODY>
</HTML>
33
AIIT - L
34
AIIT - L
PHP stands for Hypertext Preprocessor (no, the acronym doesn't follow the
name). It's an open source, server-side, scripting language used for the
development of web applications. By scripting language, we mean a program
that is script-based (lines of code) written for the automation of tasks.
35
AIIT - L
36
AIIT - L
<
Downloading XAMPP
http://localhost/hello.php.
37
AIIT - L
3.Start coding.
38
AIIT - L
with ?>:
<?php
// PHP code goes here
?>
Below,
< we have an example of a simple PHP file, with a PHP script that uses
a built-in PHP function "echo" to output the text "Hello World!" on a web page:
<html>
<body>
<?php
echo "Hello World!";
?>
</body>
</html>
40
AIIT - L
Look at the example below; only the first statement will display the value of the $color
variable! This is because $color, $COLOR, and $coLOR are treated as three different
variables: Example is as shown below
<
<html>
<body>
<?php
$color = "red";
echo "My car is " . $color . "<br>";
echo "My house is " . $COLOR . "<br>";
echo "My boat is " . $coLOR . "<br>";
?>
</body>
</html>
Output:
My car is red
My house is
My boat is
41
AIIT - L
<
42
AIIT - L
43
AIIT - L
Below,
< we have an example of a simple PHP file, with a PHP script that uses
a built-in PHP function "echo" to output the text "Hello World!" on a web page:
<html>
<body>
<?php
echo "Hello World!";
?>
</body>
</html>
44
AIIT - L
executed
45
AIIT - L
<
if (condition) {
code to be executed if condition is true;
<?php
$t = date("H");
46
AIIT - L
if (condition) {
code
< to be executed if condition is true;
} else {
code to be executed if condition is false;
}
<?php
$t = date("H");
47
AIIT - L
if (condition) {
<
code to be executed if this condition is true;
} elseif (condition) {
code to be executed if first condition is false and this condition is true;
} else {
code to be executed if all conditions are false;
}
<?php
$t = date("H");
if ($t < "10") {
echo "Have a good morning!";
} elseif ($t < "20") {
echo "Have a good day!";
} else {
echo "Have a good night!";
}
?> 48
AIIT - L
Use the switch statement to select one of many blocks of code to be executed.
Syntax
switch (n)
{
case label1:
code to be executed if n=label1;
break;
case label2:
code to be executed if n=label2;
break;
case label3:
code to be executed if n=label3;
break;
...
default:
code to be executed if n is different from all labels;
}
49
AIIT - L
<?php
$favcolor = "red";
switch ($favcolor)
{
case "red":
echo "Your favorite color is red!";
break;
case "blue":
echo "Your favorite color is blue!";
break;
case "green":
echo "Your favorite color is green!";
break;
default:
echo "Your favorite color is neither red, blue, nor green!";
}
?> 50
AIIT - L
51
AIIT - L
Syntax
while
<
(condition is true)
{
code to be executed;
}
Example : The example below displays the numbers from 1 to 5:
<?php
$x = 1;
while($x <= 5) {
echo "The number is: $x <br>";
$x++;
}
?> 52
AIIT - L
do<
{
code to be executed;
} while (condition is true);
Example
<?php
$x = 1;
do
{
echo "The number is: $x <br>";
$x++;
} while ($x <= 5);
?> 53
AIIT - L
{
code to be executed for each iteration;
}
<?php
for ($x = 0; $x <= 10; $x++) {
echo "The number is: $x <br>";
}
?>
54
AIIT - L
Output:
<
<?php
$colors = array("red", "green", "blue", "yellow");
foreach ($colors as $value) {
echo "$value <br>";
}
?>
Output:
red
green
blue
yellow 56
AIIT - L
57
AIIT - L
Associative
< arrays
These type of are arrays that use named keys that you assign to them
.
There are two ways to create an associative array:
Or
$age['Peter'] = "35";
$age['Ben'] = "37";
$age['Joe'] = "43";
58
AIIT - L
<?php
<
59
AIIT - L
<?php
<
Output:
Key=Peter, Value=35
Key=Ben, Value=37
Key=Joe, Value=43
60
AIIT - L
PROBLEM:
<
FIND THE DATA AS PER THE GIVEN FORMAT
EXAMPLE:
AJAY, 28, 0
ANIL 27 , 1
VIJAY , 19, 9
61
AIIT - L
62
AIIT - L
The DateTime() class functions allow you to get the date and time. You can
also use functions to format the date and time in many different ways.
<?php
$dt = new DateTime();
echo $dt->format('Y-m-d H:i:s');
?>
Result:-
2017-02-27 08:22:26
63
AIIT - L
?php
// Redirect browser
header("Location: http://www.geeksforgeeks.org");
exit;
?>
64
AIIT - L
65
AIIT - L
<
66
AIIT - L
Example
Result:
!dlroW olleH
67
AIIT - L
Example
Result :
Hello World
68
AIIT - L
Remove characters from both sides of a string ("He" in "Hello" and "d!" in
"World"):
<?php
$str = "Hello World!";
echo $str . "<br>";
echo trim($str,"Hed!");
?>
Result:
Hello World!
llo Worl
69
AIIT - L
Result :
70
AIIT - L
Calculate the similarity between two strings and return the matching
characters:
<?php
echo similar_text("Hello World","Hello Peter");
?>
Result :
71
AIIT - L
HELLO WORLD!
hello world 72
AIIT - L
<
https://www.w3schools.com/php/php_ref_string.asp
73
AIIT - L
<
BROWSER Investigation in php
Example
Look up the browscap.ini file and return the capabilities of the browser:
<?php
echo $_SERVER['HTTP_USER_AGENT'];
$browser = get_browser();
print_r($browser);
?>
74
AIIT - L
75
AIIT - L
<
Result:
filename: cat.gif
filename: dog.gif
filename: horse.gif
77
AIIT - L
<
PHP copy() Function
Example
Copy "source.txt" to "target.txt":
<?php
echo copy("source.txt","target.txt");
?>
78
AIIT - L
<?php
$myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!");
echo fread($myfile,filesize("webdictionary.txt"));
fclose($myfile);
?>
79
AIIT - L
Modes Description
<
r Open a file for read only. File pointer starts at the beginning of the file
Open a file for write only. Erases the contents of the file or creates a new file if it doesn't exist. File
w
pointer starts at the beginning of the file
Open a file for write only. The existing data in file is preserved. File pointer starts at the end of the
a
file. Creates a new file if the file doesn't exist
x Creates a new file for write only. Returns FALSE and an error if file already exists
r+ Open a file for read/write. File pointer starts at the beginning of the file
Open a file for read/write. Erases the contents of the file or creates a new file if it doesn't exist. File
w+
pointer starts at the beginning of the file
Open a file for read/write. The existing data in file is preserved. File pointer starts at the end of the
a+
file. Creates a new file if the file doesn't exist
x+ Creates a new file for read/write. Returns FALSE and an error if file already exists
80
AIIT - L
WRITING
<
A FILE IN PHP
<?php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "John Doe\n";
fwrite($myfile, $txt);
$txt = "Jane Doe\n";
fwrite($myfile, $txt);
fclose($myfile);
?>
81
AIIT - L
WRITING
<
A FILE IN PHP
<?php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "John Doe\n";
fwrite($myfile, $txt);
$txt = "Jane Doe\n";
fwrite($myfile, $txt);
fclose($myfile);
?>
82
AIIT - L
<
UPLOADING A FILE IN PHP
<html>
<body>
</body>
</html>
83
AIIT - L
What
<
is a Session
Although you can store data using cookies, but it has some security issues.
Since cookies are stored on user's computer it is possible for an attacker to
easily modify a cookie content to insert potentially harmful data in your
application that might break your application.
84
AIIT - L
Also,
<
every time the browser requests a URL to the server, all the cookie
data for a website is automatically sent to the server within the request. It
means if you have stored 5 cookies on user's system, each having 4KB in
size, the browser needs to upload 20KB of data each time the user views a
page, which can affect your site's performance.
85
AIIT - L
You
<
can solve both of these issues by using the PHP session. A PHP
session stores data on the server rather than user's computer. In a session
based environment, every user is identified through a unique number called
session identifier or SID. This unique session ID is used to link each user with
their own information on the server like emails, posts, etc.
86
AIIT - L
To< begin a new session, simply call the PHP session_start() function.
It will create a new session and generate a unique session ID for the user.
?php
// Starting session
session_start();
?>
87
AIIT - L
Storing
<
and Accessing Session Data
<?php
// Starting session
session_start();
// Storing session data
$_SESSION["firstname"] = “ANIL";
$_SESSION["lastname"] = “KUMAR";
?>
88
AIIT - L
<?php
Starting session
session_start();
// Accessing session data
echo 'Hi, ' . $_SESSION["firstname"] . ' ' . $_SESSION["lastname"];
?>
89
AIIT - L
<?php
<
// Starting session
session_start();
// Removing session data
if(isset($_SESSION["lastname"]))
{
unset($_SESSION["lastname"]);
}
?>
90
AIIT - L
<?php
// Starting session
<
session_start();
// Destroying session
session_destroy();
?>
91
AIIT - L
WRITING
<
A FILE IN PHP
<?php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "John Doe\n";
fwrite($myfile, $txt);
$txt = "Jane Doe\n";
fwrite($myfile, $txt);
fclose($myfile);
?>
92
AIIT - L
WRITING
<
A FILE IN PHP
<?php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "John Doe\n";
fwrite($myfile, $txt);
$txt = "Jane Doe\n";
fwrite($myfile, $txt);
fclose($myfile);
?>
93