PHP is a widely-used, open-source, server-side scripting language that is especially suited for web development. It stands for "Hypertext Preprocessor". PHP code can be embedded into HTML, making it easy to create dynamic and interactive web pages.

abhinandankondekar2 0 views 60 slides May 19, 2025
Slide 1
Slide 1 of 60
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60

About This Presentation

PHP is a widely-used, open-source, server-side scripting language that is especially suited for web development. It stands for "Hypertext Preprocessor". PHP code can be embedded into HTML, making it easy to create dynamic and interactive web pages.


Slide Content

JavaScript can "display" data in different ways:
Writing into an HTML element,
using innerHTML or innerText.
Writing into the HTML output using document.write().
Writing into an alert box, using window.alert().
Writing into the browser console, using console.log().

<html>
<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<script>
document.write(5 + 6);
Window.alert(6+7);
console.log(5 + 6);
</script>
</body>
</html>
Try it Yourself »

//Write a JavaScript function that adds two numbers and displays the result USING ALERT
<html>
<body>
<h1>JavaScript Functions</h1>
<script>
function addNumbers(a, b){
var sum = a + b;
alert("The sum is: " + sum);}
addNumbers(5, 10);
</script>
</body>
</html>

Develop a JavaScript program that calculates the area of a rectangle and displays the result
using alert().
<!DOCTYPE html>
<html>
<head>
<title>Rectangle Area Calculator</title>
<script>
function calculateArea() {
// Get length and width from the user
let length = parseFloat(prompt("Enter the length of the rectangle:"));
let width = parseFloat(prompt("Enter the width of the rectangle:"));
// Calculate the area
let area = length * width;
// Display the result
alert("The area of the rectangle is: " + area);
}
</script>
</head>
<body>
<h2>Click the button to calculate the area of a rectangle</h2>
<button onclick="calculateArea()">Calculate Area</button>
</body>
</html>

Develop a JavaScript program that takes the length, width, and height of a cuboid from the user, calculates the
volume, and displays the result using alert().
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Volume of Cuboid</title>
</head>
<body>
<script>
// Get user inputs
let length = parseFloat(prompt("Enter the length of the cuboid:"));
let width = parseFloat(prompt("Enter the width of the cuboid:"));
let height = parseFloat(prompt("Enter the height of the cuboid:"));
// Calculate volume
let volume = length * width * height;
// Display the result
alert("The volume of the cuboid is: " + volume);
</script>
</body>
</html>

PHP

•PHP
is an acronym for "PHP: Hypertext Preprocessor“
•PHP
code is executed on the server, and the result is returned to the
browser
as plain HTML
•PHP
is a widely-used, open source scripting language
•PHP
scripts are executed on the server
•PHP
is free to download and use
Department of Mechatronics Engineering 7
What is PHP?

•PHP
files can contain text, HTML, CSS, JavaScript, and PHP code
•PHP
files have extension ".php"
Department of Mechatronics Engineering 8
What is a PHP File?

•PHP
can generate dynamic page content
•PHP
can create, open, read, write, delete, and close files on the server
•PHP
can collect form data
•PHP
can send and receive cookies
•PHP
can add, delete, modify data in your database
•PHP
can be used to control user-access
•PHP
can encrypt data
Department of Mechatronics Engineering 9
What Can PHP Do?

•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.
Department of Mechatronics Engineering 10
PHP
 Syntax

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:
Department of Mechatronics Engineering 11

PHP
Case Sensitivity
In
PHP, keywords (e.g. if, else, while, echo, etc.), classes, functions, and user-
defined
functions are not case-sensitive.
<!DOCTYPE html>
<html>
<body>
<?php
ECHO "Hello
World!<br>";
echo "Hello
World!<br>";
EcHo "Hello
World!<br>";
?>
</body>
</html>
Department of Mechatronics Engineering 12
OUTPUT

Hello
World!
Hello
World!
Hello
World!

<!DOCTYPE html>
<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>
Department of Mechatronics Engineering 13
However; all variable names are case-sensitive!
Output
My
car is red
My
house is
My
boat is

In
PHP, a variable starts with the $ sign, followed by the name of the
variable:
Department of Mechatronics Engineering 14
Creating (Declaring) PHP Variables

Rules
for PHP variables:
ï‚§A
variable starts with the $ sign, followed by the name of the variable
ï‚§A
variable name must start with a letter or the underscore character
ï‚§A
variable name cannot start with a number
ï‚§A
variable name can only contain alpha-numeric characters and
underscores
(A-z, 0-9, and _ )
ï‚§Variable
names are case-sensitive ($age and $AGE are two different
variables)
Department of Mechatronics Engineering 15
PHP Variables

<!DOCTYPE
html>
<html>
<body>
<?php
$txt
= "sanjivani";
echo
"I love $txt!";
?>
</body>
</html>
Department of Mechatronics Engineering 16

<!DOCTYPE
html>
<html>
<body>
<?php
$x
= 5;
$y
= 4;
echo
$x + $y;
?>
</body>
</html>
Department of Mechatronics Engineering 17

•PHP
supports the following data types:
•String
•Integer
•Float
(floating point numbers - also called double)
•Boolean
•Array
Department of Mechatronics Engineering 18
PHP Data Types

Department of Mechatronics Engineering 19
PHP Strings

<?php
$x
= 5985;
$y
= 10.365;
var_dump($x);
var_dump($y);
?>
Department of Mechatronics Engineering 20

Department of Mechatronics Engineering 21
Array

•strlen()
- Return the Length of a String
•str_word_count()
- Count Words in a String
•strrev()
- Reverse a String
•strpos()
- Search For a Text Within a String
•str_replace()
- Replace Text Within a String
<?php
echo strrev("Hello
world!");  // outputs !dlrow olleH
echo str_word_count("Hello
world!");  // outputs 2
echo strrev("Hello
world!");  // outputs !dlrow olleH
echo strpos("Hello
world!", "world");  // outputs 6
echo str_replace("world", "Dolly", "Hello
world!"); // outputs Hello Dolly!
?>
Department of Mechatronics Engineering 22
PHP Strings

•PHP
pi() Function
•PHP
min() and max() Functions
•PHP
abs() Function
•PHP
sqrt() Function
•PHP
round() Function
<?php
echo(pi()); //
returns 3.1415926535898
echo(min(0, 150, 30, 20,
-8, -200));  // returns -200
echo(abs(-6.7));  //
returns 6.7
echo(sqrt(64));  //
returns 8
echo(round(0.60));  //
returns 1
?>
Department of Mechatronics Engineering 23
PHP Math

Department of Mechatronics Engineering 24
PHP Arithmetic Operators

Department of Mechatronics Engineering 25

Department of Mechatronics Engineering 26
•Write
a PHP script to check whether a number is even or odd.
<?php
$num = 7;
if
($num % 2 == 0) { echo "Even number";}
else
{echo "Odd number";}
?>

Department of Mechatronics Engineering 27
What is Form

Department of Mechatronics Engineering 28

Department of Mechatronics Engineering 29

Department of Mechatronics Engineering 30

Department of Mechatronics Engineering 31

Department of Mechatronics Engineering 32
<html>  
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>

Department of Mechatronics Engineering 33
<!DOCTYPE HTML>
<html>  
<body>
<form action="welcome_get.php" method="get">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>

Department of Mechatronics Engineering 34
When to use GET?
•Information
sent from a form with the GET method is 
visible to everyone (all
variable
names
and values are displayed in the URL).
• GET
also has limits on the amount of information to send.
•The
limitation is about 2000 characters.
•it
is possible to bookmark the page. 
When to use POST?
•Information
sent from a form with the POST method is 
invisible to others (all

names/values
are embedded within the body of the HTTP request)
•has no limits on
the amount of information to send.
•it
is not possible to bookmark the page.

Department of Mechatronics Engineering 35

Department of Mechatronics Engineering 36

Department of Mechatronics Engineering 37

Department of Mechatronics Engineering 38

Department of Mechatronics Engineering 39

Department of Mechatronics Engineering 40

Department of Mechatronics Engineering 41

Department of Mechatronics Engineering 42

Department of Mechatronics Engineering 43

Department of Mechatronics Engineering 44

Department of Mechatronics Engineering 45

Department of Mechatronics Engineering 46

Department of Mechatronics Engineering 47

Department of Mechatronics Engineering 48

Department of Mechatronics Engineering 49

Department of Mechatronics Engineering 50

Department of Mechatronics Engineering 51

Department of Mechatronics Engineering 52

Department of Mechatronics Engineering 53

Department of Mechatronics Engineering 54

Department of Mechatronics Engineering 55

Department of Mechatronics Engineering 56

Department of Mechatronics Engineering 57

Department of Mechatronics Engineering 58

Department of Mechatronics Engineering 59

Department of Mechatronics Engineering 60
Tags