0% found this document useful (0 votes)
2 views

Module 1 Lecture 3

The document provides an overview of HTML and PHP, detailing the structure of HTML documents, the use of block-level and inline elements, and basic HTML tags. It also covers the fundamentals of PHP, including its syntax, conditional statements, and loops. Additionally, it includes examples and exercises for creating web forms and using PHP for server-side scripting.

Uploaded by

drshantanushahi
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Module 1 Lecture 3

The document provides an overview of HTML and PHP, detailing the structure of HTML documents, the use of block-level and inline elements, and basic HTML tags. It also covers the fundamentals of PHP, including its syntax, conditional statements, and loops. Additionally, it includes examples and exercises for creating web forms and using PHP for server-side scripting.

Uploaded by

drshantanushahi
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 93

AIIT - L

1
AIIT - L

2
AIIT - L

What is the HTML document structure?

An HTML 5 document is composed of three parts: a line containing HTML


version information, a declarative header section (delimited by the HEAD
element), a body, which contains the document's actual content.

What is the main use of HTML?

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

•A block-level element always starts on a new line.


•A block-level element always takes up the full width available (stretches out
to the left and right as far as it can).
•A block level element has a top and a bottom margin,
<html>
<body>

<div style="border: 1px solid black">Hello World</div>

<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

•An inline element does not start on a new line.

•An inline element only takes up as much width as


necessary.
<html>
<body>
<p>This is an inline span <span style="border: 1px solid black">Hello
World</span> element inside a paragraph.</p>

<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

This is an inline span Hello World element inside a


paragraph.

The SPAN element is an inline element and will not start on


a new line and only takes up as much width as necessary.

7
AIIT - L

SOME BASIC TAGS AND ITS USAGE

<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

ORDERED AND UNORDERED LISTING IN HTML

<OL>
<LI>
</OL>

<UL>
<LI>
</UL>

9
AIIT - L

ORDERED AND UNORDERED LISTING IN HTML

Exercise:

Design the Programme and Course Brochure of a University


using Ordered and Unordered listing in HTML.

THE MAIN AIM IS TO SEE HOW YOU ARE APPLYING OL


AND UL AT NESTED LEVELS

10
AIIT - L

A webform, web form or HTML form on a web page


allows a user to enter data that is sent to a server
for processing.

Forms can resemble paper or database .

11
AIIT - L

The different input types are as follows:

•<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

<form name=”myform” action="action_page.php" method="get">

14
AIIT - L

SELECT TAG

<select name="cars" id="cars">


<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>

15
AIIT - L

TEXTAREA TAG

<textarea id=“FEEDBACK" name=“custfeedback" rows="4" cols="50">

Please provide the customers feedback here

</textarea>

16
AIIT - L

autofocus

Specifies that a text area should automatically get focus when the
page loads

17
AIIT - L

Specifies the maximum


maxlength number number of characters
allowed in the text area

18
AIIT - L

Specifies a short hint


that describes the
placeholder text
expected value of a text
area

19
AIIT - L

• Design a web form to the best of your present


knowledge to make a provision for lodging a Police
Complaint by the person who wants to do so.

First decide the necessary fields to be taken, decide


screen positioning of the fields, collect images to be
used before hand , apply links and ready your web form.

Don’t forget to apply validations in the fields. Validations


will improve the quality of your form and the website.

20
AIIT - L

HTML frames are used to divide your browser window into


multiple sections where each section can load a separate
HTML document.

A collection of frames in the browser window is known as a


frameset. The window is divided into frames in a similar
way the tables are organized: into rows and columns.

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> &nbsp &nbsp &nbsp

<TD> <A HREF="https://www.ndtv.com" TARGET="RIGHTTOP"> NDTV


</A>&nbsp &nbsp &nbsp
<TD> <A HREF="MYVIDEO.HTM" TARGET="RIGHTBOTTOM"> MY OWN VIDEO
</A>
</TABLE>

</BODY>

</HTML>
27
AIIT - L

<BODY>
<CENTER>
YOU ARE WELCOME
</CENTER>

</BODY>

28
AIIT - L

<MARQUEE> HELLO </MARQUEE>

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

<TABLE NAME="T1" BORDER=7 WIDTH=80% HEIGHT=80% CELLPADDING = 5


CELLSPACING =5>
<

<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>MON<TD>LECTURE-1<TD>LECTURE-2<TD>LECTURE-


3<TD>LECTURE-4<TD ROWSPAN=5><FONT COLOR=RED><B>LUNCH</B></FONT>
<TD>LECTURE-5<TD>LECTURE-6<TD>LECTURE-7

<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

What is PHP and why it is used?


<

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

Is PHP front end or backend?


<

PHP is considered a backend scripting language. PHP scripts are usually


written on a server that the front-end, or client side code would interact with.

36
AIIT - L

<

Downloading XAMPP

Download. XAMPP is an easy to install Apache distribution containing


MariaDB, PHP, and Perl. Just download and start the installer. It's that easy.
XAMPP for Windows 7.2.33, 7.3.21 & 7.4.9 ... md5; sha1. Download (64 bit),
154 Mb.

http://localhost/hello.php.

37
AIIT - L

How do I start working in PHP?


<

You need two things to get started: a development environment to run


your PHP scripts and a code editor to write the code.

1.Install a local development environment. PHP is a scripting language. ...


2.Install a code editor. A code editor is basically an advanced text editor that
helps you writing your code. ...

3.Start coding.

38
AIIT - L

Basic PHP Syntax


<
A PHP script can be placed anywhere in the
document A PHP script starts with <?php and ends
..

with ?>:

<?php
// PHP code goes here
?>

The default file extension for PHP files is ".php".


A PHP file normally contains HTML tags, and
some PHP scripting code.
39
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>

<h1>My first PHP page</h1>

<?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>

<h1>My first PHP page</h1>

<?php
echo "Hello World!";
?>

</body>
</html>

44
AIIT - L

In PHP we have the following conditional statements:


<

•if statement - executes some code if one condition is true


•if...else statement - executes some code if a condition is true and
another code if that condition is false
•if...elseif...else statement - executes different codes for more than two
conditions
•switch statement - selects one of many blocks of code to be

executed

45
AIIT - L

<

if (condition) {
code to be executed if condition is true;

<?php
$t = date("H");

if ($t < "20")


{
echo "Have a good day!";
}
?>

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");

if ($t < "20") {


echo "Have a good day!";
} else {
echo "Have a good night!";
}
?>

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

The PHP switch Statement


<

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

The PHP switch Statement


<

<?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

In PHP, we have the following loop types:


<

•while - loops through a block of code as long as the specified


condition is true

•do...while - loops through a block of code once, and then repeats


the loop as long as the specified condition is true

•for - loops through a block of code a specified number of times

•foreach - loops through a block of code for each element in an array

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

for (init counter; test counter; increment counter)


<

{
code to be executed for each iteration;
}

<?php
for ($x = 0; $x <= 10; $x++) {
echo "The number is: $x <br>";
}
?>

Output : In next Slide

54
AIIT - L

Output:
<

The number is: 0


The number is: 10
The number is: 20
The number is: 30
The number is: 40
The number is: 50
The number is: 60
The number is: 70
The number is: 80
The number is: 90
The number is: 100
55
AIIT - L

foreach ($array as $value)


{<
code to be executed;
}

<?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:

$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");

Or

$age['Peter'] = "35";
$age['Ben'] = "37";
$age['Joe'] = "43";

58
AIIT - L

<?php
<

$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");


echo "Peter is " . $age['Peter'] . " years old.";
?>

59
AIIT - L

<?php
<

$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");

foreach($age as $x => $x_value)


{
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
?>

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

TOPPER NAME, MARKS

SECOND TOPPER NAME, MARKS, TRAILING BEHIND BY HOW MANY


MARKS TO BECOME TOPPER

THIRD TOPPER NAME, MARKS, TRAILING BEHIND BY HOW MANY


MARKS TO BECOME TOPPER

EXAMPLE:

AJAY, 28, 0
ANIL 27 , 1
VIJAY , 19, 9
61
AIIT - L

62
AIIT - L

Using DateTime() Class:

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

Browser Redirection in php:


<

?php

// Redirect browser

header("Location: http://www.geeksforgeeks.org");
exit;

?>

64
AIIT - L

Manipulating PHP Strings


<

PHP provides many built-in functions for manipulating


strings like calculating the length of a string, find
substrings or characters, replacing part of a string with
different characters, take a string apart, and many
others.

65
AIIT - L

<

66
AIIT - L

PHP strrev() Function


<

Example

Reverse the string "Hello World!":


<?php
echo strrev("Hello World!");
?>

Result:

!dlroW olleH

67
AIIT - L

PHP ucwords() Function


<

Example

Convert the first character of each word to uppercase:


<?php
echo ucwords("hello world");
?>

Result :

Hello World

68
AIIT - L

PHP trim() Function


<
Example

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

PHP substr_count() Function


<
Example

Count the number of times "world" occurs in the string:


<?php
echo substr_count("Hello world. The world is nice","world");
?>

Result :

70
AIIT - L

PHP similar_text() Function


<
Example

Calculate the similarity between two strings and return the matching
characters:
<?php
echo similar_text("Hello World","Hello Peter");
?>

Result :

71
AIIT - L

PHP strtoupper() Function


Example
<

Convert all characters to uppercase:


<?php
echo strtoupper("Hello WORLD!");
?>

HELLO WORLD!

PHP strtolower() Function


Example
Convert all characters to lowercase:
<?php
echo strtolower("Hello WORLD.");
?>

hello world 72
AIIT - L

<
https://www.w3schools.com/php/php_ref_string.asp

73
AIIT - L

<
BROWSER Investigation in php

PHP get_browser() Function

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

PHP readdir() Function


<
Example
List all entries in the images directory, then close
:
<?php
$dir = "/images/";

// Open a directory, and read its contents


if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
echo "filename:" . $file . "<br>";
}
closedir($dh);
}
}
?> 76
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

READING A FILE AND THEN CLOSING A FILE IN PHP


<
EXAMPLE:

<?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>

<form action="upload.php" method="post" ">


Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit“>
</form>

</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

Accessing Session Data


<

<?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

You might also like