SlideShare a Scribd company logo
CN5109
WEB APPLICATION
DEVELOPMENT
Chapter 1
Introduction to Server-Side Development with PHP
What is Server-Side Development?
• The basic hosting of your files is achieved through a web
server.
• Server-side development is much more than web hosting: it
involves the use of a programming technology like PHP or ASP
to create scripts that dynamically generate content.
• Server-side scripting is a method of designing websites so
that the process or user request is run on the originating
server.
• Server-side scripts provide an interface to the user and are
used to limit access to proprietary data and help keep control
of the script source code.
What is Server-Side Development?
Server-Side Scripting Examples
• ActiveVFP
• ASP
• C
• DC
• Java
• JavaScript (using Server-side JavaScript (SSJS) e.g., node.js)
• Perl
• PHP
• Python
• R
• Ruby
Client-side vs. Server-side Scripting
Client-side Environment
• The client-side environment used to run scripts is usually a
browser.
• The processing takes place on the end users computer.
• The source code is transferred from the web server to the
users computer over the internet and run directly in the
browser.
• The scripting language needs to be enabled on the client
computer.
• Sometimes if a user is conscious of security risks they may
switch the scripting facility off.
• When this is the case a message usually pops up to alert the
user when script is attempting to run.
Client-side vs. Server-side Scripting
Server-side Environment
• The server-side environment that runs a scripting language is
a web server.
• A user's request is fulfilled by running a script directly on the
web server to generate dynamic HTML pages.
• This HTML is then sent to the client browser.
• It is usually used to provide interactive web sites that interface
to databases or other data stores on the server.
• This is different from client-side scripting where scripts are run
by the viewing web browser, usually in JavaScript.
• The primary advantage to server-side scripting is the ability to
highly customize the response based on the user's
requirements, access rights, or queries into data stores.
Client-side vs. Server-side Scripting
1. Client page request
2. Decision making
based on requested
page code content
3. HTML
output
returned to
browser
Introduction to PHP
• Created by Rasmus Lerdorf in 1994 and publicly released June
8, 1995
• PHP, which is short for PHP: Hypertext Preprocessor, is a
server-side interpreted scripting language.
• It was designed for creating dynamic web pages and web
pages that effectively work with databases.
• Files that include PHP code on a web server may have any file
extension, but most commonly they end in .PHP, .PHP3, or
.PHTML.
• A PHP file can be created and the contents can be viewed by
using a programming code editing program, such as
Dreamweaver or Notepad++.
Common Use of PHP
• 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
Advantages of PHP
• PHP runs on various platforms (Windows, Linux, Unix, Mac OS
X, etc.)
• PHP is compatible with almost all servers used today (Apache,
IIS, etc.)
• PHP supports a wide range of databases
• PHP is free.
• PHP is easy to learn and runs efficiently on the server side
PHP - Environment Setup
• In order to develop and run PHP Web pages three vital
components need to be installed on your computer system.
• Web Server − PHP will work with virtually all Web Server
software, including Microsoft's Internet Information Server
(IIS) but then most often used is freely available Apache
Server.
• Database − PHP will work with virtually all database software,
including Oracle and Sybase but most commonly used is freely
available MySQL database.
• PHP Parser − In order to process PHP script instructions a
parser must be installed to generate HTML output that can be
sent to the Web Browser.
Quiz
1. Define Server Scripting Language
2. Give any four examples of Server Scripting Language
3. Discuss any four common use of PHP.
4. Discuss any four advantages of PHP.
PHP Installation
• To start using PHP, you can:
• Find a web host with PHP and MySQL support
• Install a web server on your own PC, and then install PHP and
MySQL
• If your server has activated support for PHP you do not need
to do anything.
• Just create some .php files, place them in your web directory,
and the server will automatically parse them for you.
• You do not need to compile anything or install any extra tools.
• Because PHP is free, most web hosts offer PHP support.
PHP Installation
• However, if your server does not support PHP, you must:
• install a web server (XAMPP, WAMP)
• install PHP
• install a database, such as MySQL
Write PHP Online
• Write PHP Online is an online code editor which helps you to
write and test run/execute your php code online from your
browser.
• This is one of the simple and powerfull online php code editor
tool available on the internet.
• Write PHP Online supports all PHP functionalities and it runs
using PHP version 7.
http://www.writephponline.com/
Write PHP Online
1. Write the PHP Code.
2. Click the “Run Code” button to see the output.
PHP Syntax
• A PHP script is executed on the server, and the plain HTML
result is sent back to the browser.
• A PHP script can be placed anywhere in the document.
• A PHP script starts with <?php and ends with ?>.
• PHP statements are terminated by a semicolon (;)
• The default file extension for PHP files is ".php".
• A PHP file normally contains HTML tags, and some PHP
scripting code.
PHP Syntax
• Example
<?php
echo "Hello World!";
?>
Output:
PHP in HTML
• PHP is designed to interact with HTML and PHP scripts can be
included in an HTML page without a problem.
• In an HTML page, PHP code is enclosed within special PHP
tags.
<html>
<body>
<?php
echo "Hello World!";
?>
</body>
</html>
HTML in PHP
• To write HTML code in PHP file, you need to use Echo or Print
statement.
<?php
echo “Hello World”;
echo “<h1> Hello World</h1>”;
?>
Output:
Echo/ Print Statement
• Used to output data to the screen.
• The echo statement can be used with or without parentheses:
echo or echo().
<?php
echo "Hello world!";
echo 123;
?>
Output:
Echo / Print Statement
• Using HTML tags in PHP:
<?php
echo “Hello”;
echo “<br>”;
echo “World”;
?>
<?php
echo “Hello <br> World”;
?>
Try This
<?php
echo "<table border=1 width=500>";
echo "<tr>";
echo "<td>1</td><td>2</td>";
echo "</tr>";
echo "<tr>";
echo "<td>3</td><td>4</td>";
echo "</tr>";
echo "</table>";
?>
Output:
Quiz
Write a PHP code to display the following outputs:
a. Welcome to FTMS College
b. University of East London
c. CN5109
Web
Application
Development
Variables
• Variables are "containers" for storing information.
• In PHP, a variable starts with the $ sign, followed by the name
of the variable
Note: When you assign a text value to a variable, put quotes
around the value.
Note: Unlike other programming languages, PHP has no
command for declaring a variable. It is created the moment you
first assign a value to it.
$txt = "Hello world!";
$x = 5;
$y = 10.5;
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)
Quiz
Determine whether these variable names are valid or not valid.
a. text
b. $txt1
c. $1txt
d. $txt 1
e. $txt#1
f. $txt_1
Comments in PHP
• A comment in PHP code is a line that is not read/executed as
part of the program. Its only purpose is to be read by
someone who is looking at the code.
• Comments can be used to:
• Let others understand what you are doing
• Remind yourself of what you did - Most programmers
have experienced coming back to their own work a
year or two later and having to re-figure out what they
did. Comments can remind you of what you were
thinking when you wrote the code
Comments in PHP
<?php
// This is a single-line comment
# This is also a single-line comment
/*
This is a multiple-lines comment block
that spans over multiple
lines
*/
echo “This is not a comment”;
?>
Data Types
• Variables can store data of different types, and different data
types can do different things.
• Data types are declarations for variables. This determines the
type and size of data associated with variables.
• PHP supports the following data types:
• String
• Integer
• Float (floating point numbers - also called double)
• Boolean
• Array
• NULL
Data Types - String
• A string is a sequence of characters, like "Hello world!".
• A string can be any text inside quotes.
<?php
$x = "Hello world!";
$y = “Hi There!”;
echo $x;
echo "<br>";
echo $y;
?>
Data Types - Integer
• An integer data type is a non-decimal number between -
2,147,483,648 and 2,147,483,647.
• Rules for integers:
• An integer must have at least one digit
• An integer must not have a decimal point
• An integer can be either positive or negative
• Integers can be specified in three formats: decimal (10-based),
hexadecimal (16-based - prefixed with 0x) or octal (8-based -
prefixed with 0)
<?php
$x = 5985;
echo $x;
?>
Data Types - Float
• A float (floating point number) is a number with a decimal
point or a number in exponential form.
• In the following example $x is a float.
• The PHP var_dump() function returns the data type and value.
<?php
$x = 10.365;
echo $x;
?>
Data Types - Boolean
• A Boolean represents two possible states: TRUE or FALSE.
• Booleans are often used in conditional testing.
$x = true;
$y = false;
echo $x;
Data Types - Array
• An array stores multiple values in one single variable.
• In the following example $cars is an array.
<?php
$cars = array("Volvo","BMW","Toyota","Honda");
echo $cars[0],"<br>";
echo $cars[1],"<br>";
echo $cars[2],"<br>";
echo $cars[3],"<br>";
?>
Data Types - Null
• Null is a special data type which can have only one value:
NULL.
• A variable of data type NULL is a variable that has no value
assigned to it.
• Tip: If a variable is created without a value, it is automatically
assigned a value of NULL.
• Variables can also be emptied by setting the value to NULL
<?php
$x = null;
echo $x;
?>
Quiz
Identify the data type of the following data:
a. “Cyberjaya”
b. 1.35
c. 50
d. True
e. A
f. “False”
g.
h. 1, 2, 4, 8
i. “25”
Operator
• Operators are used to perform mathematical operations on
variables and values.
• PHP divides the operators in the following groups:
• Arithmetic operators
• Assignment operators
• Comparison operators
• Increment/Decrement operators
• Logical operators
• String operators
• Array operators
Arithmetic Operators
• Arithmetic operators are used with numeric values to perform
common arithmetical operations, such as addition,
subtraction, multiplication etc.
Operation Name Example Result
+ Addition $x + $y Sum of $x and $y
- Subtraction $x - $y
Difference of $x
and $y
* Multiplication $x * $y
Product of $x
and $y
/ Division $x / $y
Quotient of $x
and $y
% Modulus $x % $y
Remainder of $x
divided by $y
Arithmetic Operators
• Example
$x = 10;
$y = 5;
echo $x + $y,"<br>";
echo $x - $y,"<br>";
echo $x * $y,"<br>";
echo $x / $y,"<br>";
echo $x % $y,"<br>";
Output:
Comparison Operators
• The PHP comparison operators are used to compare two
values (number or string).
Operator Name Example Result
== Equal $x == $y Returns true if $x is equal to $y
!= Not equal $x != $y Returns true if $x is not equal to $y
<> Not equal $x <> $y Returns true if $x is not equal to $y
>
Greater
than
$x > $y Returns true if $x is greater than $y
< Less than $x < $y Returns true if $x is less than $y
>=
Greater
than or
equal to
$x >= $y Returns true if $x is greater than or equal to $y
<=
Less than
or equal to
$x <= $y Returns true if $x is less than or equal to $y
Comparison Operators
• Example
$x = 10;
$y = 5;
echo $x == $y,"<br>";
echo $x <> $y,"<br>";
echo $x < $y,"<br>";
echo $x > $y,"<br>";
Output:
Increment /Decrement Operators
• Increment operators are used to increment a variable's value.
• Decrement operators are used to decrement a variable's
value.
Operator Name Description
++$x Pre-increment
Increments $x by one, then returns
$x
$x++ Post-increment
Returns $x, then increments $x by
one
--$x Pre-decrement
Decrements $x by one, then returns
$x
$x-- Post-decrement
Returns $x, then decrements $x by
one
Increment /Decrement Operators
• Example
$x = 10;
echo $x ,"<br>";
echo ++$x ,"<br>";
echo $x ,"<br>";
echo $x++ ,"<br>";
Output:
Logical Operators
• Example
Operator Name Example Result
and And $x and $y True if both $x and $y are true
or Or $x or $y True if either $x or $y is true
xor Xor $x xor $y
True if either $x or $y is true,
but not both
&& And $x && $y True if both $x and $y are true
|| Or $x || $y True if either $x or $y is true
! Not !$x True if $x is not true
Logical Operators
• Example
$x = 100;
$y = 50;
if ($x == 100 and $y == 50) {
echo "Hello world!";
}
Output:
Quiz
Solve the following equations:
Given $x = 10 and $y = 5
a. $x + $x + $y
b. $x - $y + $x
c. $x + $y * $x
d. $x / $y + $x
e. $x > $y
f. $y != $x
g. ++$x
h. $y--

More Related Content

What's hot (20)

Cryptanalysis of autokey cipher
Cryptanalysis of autokey cipherCryptanalysis of autokey cipher
Cryptanalysis of autokey cipher
Harshil Darji
 
Code Generation
Code GenerationCode Generation
Code Generation
PrabuPappuR
 
Microkernel
MicrokernelMicrokernel
Microkernel
Suraj Mehta
 
3 describing syntax
3 describing syntax3 describing syntax
3 describing syntax
Munawar Ahmed
 
Corba concepts & corba architecture
Corba concepts & corba architectureCorba concepts & corba architecture
Corba concepts & corba architecture
nupurmakhija1211
 
Deadlock in distribute system by saeed siddik
Deadlock in distribute system by saeed siddikDeadlock in distribute system by saeed siddik
Deadlock in distribute system by saeed siddik
Saeed Siddik
 
Distributed Systems
Distributed SystemsDistributed Systems
Distributed Systems
vampugani
 
Passes of Compiler.pptx
Passes of Compiler.pptxPasses of Compiler.pptx
Passes of Compiler.pptx
Sanjay Singh
 
Procedural vs. object oriented programming
Procedural vs. object oriented programmingProcedural vs. object oriented programming
Procedural vs. object oriented programming
Haris Bin Zahid
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
Akshaya Arunan
 
Oomd unit1
Oomd unit1Oomd unit1
Oomd unit1
VivekChaudhary93
 
Instruction Set Architecture
Instruction Set ArchitectureInstruction Set Architecture
Instruction Set Architecture
Dilum Bandara
 
Distributed web based systems
Distributed web based systemsDistributed web based systems
Distributed web based systems
Reza Gh
 
Object modeling techniques by savyasachi
Object modeling techniques by savyasachiObject modeling techniques by savyasachi
Object modeling techniques by savyasachi
Savyasachi14
 
Compiler Design Unit 5
Compiler Design Unit 5Compiler Design Unit 5
Compiler Design Unit 5
Jena Catherine Bel D
 
Module 2
Module 2 Module 2
Module 2
ShwetaNirmanik
 
Software engineering mca
Software engineering mcaSoftware engineering mca
Software engineering mca
Aman Adhikari
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introduction
Rana Ehtisham Ul Haq
 
Servlet life cycle
Servlet life cycleServlet life cycle
Servlet life cycle
Venkateswara Rao N
 
Avro
AvroAvro
Avro
Eric Turcotte
 
Cryptanalysis of autokey cipher
Cryptanalysis of autokey cipherCryptanalysis of autokey cipher
Cryptanalysis of autokey cipher
Harshil Darji
 
Corba concepts & corba architecture
Corba concepts & corba architectureCorba concepts & corba architecture
Corba concepts & corba architecture
nupurmakhija1211
 
Deadlock in distribute system by saeed siddik
Deadlock in distribute system by saeed siddikDeadlock in distribute system by saeed siddik
Deadlock in distribute system by saeed siddik
Saeed Siddik
 
Distributed Systems
Distributed SystemsDistributed Systems
Distributed Systems
vampugani
 
Passes of Compiler.pptx
Passes of Compiler.pptxPasses of Compiler.pptx
Passes of Compiler.pptx
Sanjay Singh
 
Procedural vs. object oriented programming
Procedural vs. object oriented programmingProcedural vs. object oriented programming
Procedural vs. object oriented programming
Haris Bin Zahid
 
Instruction Set Architecture
Instruction Set ArchitectureInstruction Set Architecture
Instruction Set Architecture
Dilum Bandara
 
Distributed web based systems
Distributed web based systemsDistributed web based systems
Distributed web based systems
Reza Gh
 
Object modeling techniques by savyasachi
Object modeling techniques by savyasachiObject modeling techniques by savyasachi
Object modeling techniques by savyasachi
Savyasachi14
 
Software engineering mca
Software engineering mcaSoftware engineering mca
Software engineering mca
Aman Adhikari
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introduction
Rana Ehtisham Ul Haq
 

Similar to Web Application Development using PHP Chapter 1 (20)

lec1 (1).pptxkeoiwjwoijeoiwjeoijwoeijewoi
lec1 (1).pptxkeoiwjwoijeoiwjeoijwoeijewoilec1 (1).pptxkeoiwjwoijeoiwjeoijwoeijewoi
lec1 (1).pptxkeoiwjwoijeoiwjeoijwoeijewoi
PedakotaPavankumar
 
Php unit i
Php unit iPhp unit i
Php unit i
BagavathiLakshmi
 
Introduction to PHP.pptx
Introduction to PHP.pptxIntroduction to PHP.pptx
Introduction to PHP.pptx
MarianJRuben
 
Php intro
Php introPhp intro
Php intro
sana mateen
 
introduction to php and its uses in daily
introduction to php and its uses in dailyintroduction to php and its uses in daily
introduction to php and its uses in daily
vishal choudhary
 
1. introduction to php and variable
1. introduction to php and variable1. introduction to php and variable
1. introduction to php and variable
NurAliaAqilaMuhalis
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
Meetendra Singh
 
Php reports sumit
Php reports sumitPhp reports sumit
Php reports sumit
Sumit Biswas
 
Introduction to PHP.pptx
Introduction to PHP.pptxIntroduction to PHP.pptx
Introduction to PHP.pptx
SherinRappai
 
INTRODUCTION ON PHP - SERVER SIDE SCRIPTING LANGUAGE
INTRODUCTION ON PHP - SERVER SIDE SCRIPTING LANGUAGEINTRODUCTION ON PHP - SERVER SIDE SCRIPTING LANGUAGE
INTRODUCTION ON PHP - SERVER SIDE SCRIPTING LANGUAGE
PRIYADARSINIK3
 
php Chapter 1.pptx
php Chapter 1.pptxphp Chapter 1.pptx
php Chapter 1.pptx
HambaAbebe2
 
php basic part one
php basic part onephp basic part one
php basic part one
jeweltutin
 
Php unit i
Php unit i Php unit i
Php unit i
prakashvs7
 
PHP MySQL Workshop - facehook
PHP MySQL Workshop - facehookPHP MySQL Workshop - facehook
PHP MySQL Workshop - facehook
Shashank Skills Academy
 
Materi Dasar PHP
Materi Dasar PHPMateri Dasar PHP
Materi Dasar PHP
Robby Firmansyah
 
introduction to php notes for engineering students.ppt
introduction to php notes for engineering students.pptintroduction to php notes for engineering students.ppt
introduction to php notes for engineering students.ppt
manju451965
 
waptLab 04.pdfwaptLab09 tis lab is used for college lab exam
waptLab 04.pdfwaptLab09 tis lab is used for college lab examwaptLab 04.pdfwaptLab09 tis lab is used for college lab exam
waptLab 04.pdfwaptLab09 tis lab is used for college lab exam
imgautam076
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
Alokin Software Pvt Ltd
 
PHP ITCS 323
PHP ITCS 323PHP ITCS 323
PHP ITCS 323
Sleepy Head
 
Php
PhpPhp
Php
Ajay Kumar
 
lec1 (1).pptxkeoiwjwoijeoiwjeoijwoeijewoi
lec1 (1).pptxkeoiwjwoijeoiwjeoijwoeijewoilec1 (1).pptxkeoiwjwoijeoiwjeoijwoeijewoi
lec1 (1).pptxkeoiwjwoijeoiwjeoijwoeijewoi
PedakotaPavankumar
 
Introduction to PHP.pptx
Introduction to PHP.pptxIntroduction to PHP.pptx
Introduction to PHP.pptx
MarianJRuben
 
introduction to php and its uses in daily
introduction to php and its uses in dailyintroduction to php and its uses in daily
introduction to php and its uses in daily
vishal choudhary
 
1. introduction to php and variable
1. introduction to php and variable1. introduction to php and variable
1. introduction to php and variable
NurAliaAqilaMuhalis
 
Introduction to PHP.pptx
Introduction to PHP.pptxIntroduction to PHP.pptx
Introduction to PHP.pptx
SherinRappai
 
INTRODUCTION ON PHP - SERVER SIDE SCRIPTING LANGUAGE
INTRODUCTION ON PHP - SERVER SIDE SCRIPTING LANGUAGEINTRODUCTION ON PHP - SERVER SIDE SCRIPTING LANGUAGE
INTRODUCTION ON PHP - SERVER SIDE SCRIPTING LANGUAGE
PRIYADARSINIK3
 
php Chapter 1.pptx
php Chapter 1.pptxphp Chapter 1.pptx
php Chapter 1.pptx
HambaAbebe2
 
php basic part one
php basic part onephp basic part one
php basic part one
jeweltutin
 
introduction to php notes for engineering students.ppt
introduction to php notes for engineering students.pptintroduction to php notes for engineering students.ppt
introduction to php notes for engineering students.ppt
manju451965
 
waptLab 04.pdfwaptLab09 tis lab is used for college lab exam
waptLab 04.pdfwaptLab09 tis lab is used for college lab examwaptLab 04.pdfwaptLab09 tis lab is used for college lab exam
waptLab 04.pdfwaptLab09 tis lab is used for college lab exam
imgautam076
 
Ad

More from Mohd Harris Ahmad Jaal (20)

Fundamentals of Programming Chapter 7
Fundamentals of Programming Chapter 7Fundamentals of Programming Chapter 7
Fundamentals of Programming Chapter 7
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 6
Fundamentals of Programming Chapter 6Fundamentals of Programming Chapter 6
Fundamentals of Programming Chapter 6
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 4
Fundamentals of Programming Chapter 4Fundamentals of Programming Chapter 4
Fundamentals of Programming Chapter 4
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 3
Fundamentals of Programming Chapter 3Fundamentals of Programming Chapter 3
Fundamentals of Programming Chapter 3
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 2
Fundamentals of Programming Chapter 2Fundamentals of Programming Chapter 2
Fundamentals of Programming Chapter 2
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 1
Fundamentals of Programming Chapter 1Fundamentals of Programming Chapter 1
Fundamentals of Programming Chapter 1
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 8
Web Application Development using PHP Chapter 8Web Application Development using PHP Chapter 8
Web Application Development using PHP Chapter 8
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 7
Web Application Development using PHP Chapter 7Web Application Development using PHP Chapter 7
Web Application Development using PHP Chapter 7
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 6
Web Application Development using PHP Chapter 6Web Application Development using PHP Chapter 6
Web Application Development using PHP Chapter 6
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 4
Web Application Development using PHP Chapter 4Web Application Development using PHP Chapter 4
Web Application Development using PHP Chapter 4
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 10
Fundamentals of Computing Chapter 10Fundamentals of Computing Chapter 10
Fundamentals of Computing Chapter 10
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 9
Fundamentals of Computing Chapter 9Fundamentals of Computing Chapter 9
Fundamentals of Computing Chapter 9
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 8
Fundamentals of Computing Chapter 8Fundamentals of Computing Chapter 8
Fundamentals of Computing Chapter 8
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 7
Fundamentals of Computing Chapter 7Fundamentals of Computing Chapter 7
Fundamentals of Computing Chapter 7
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 6
Fundamentals of Computing Chapter 6Fundamentals of Computing Chapter 6
Fundamentals of Computing Chapter 6
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 5
Fundamentals of Computing Chapter 5Fundamentals of Computing Chapter 5
Fundamentals of Computing Chapter 5
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 8
Web Application Development using PHP Chapter 8Web Application Development using PHP Chapter 8
Web Application Development using PHP Chapter 8
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 7
Web Application Development using PHP Chapter 7Web Application Development using PHP Chapter 7
Web Application Development using PHP Chapter 7
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 6
Web Application Development using PHP Chapter 6Web Application Development using PHP Chapter 6
Web Application Development using PHP Chapter 6
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 4
Web Application Development using PHP Chapter 4Web Application Development using PHP Chapter 4
Web Application Development using PHP Chapter 4
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2
Mohd Harris Ahmad Jaal
 
Ad

Recently uploaded (20)

Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
How to Manage Allocations in Odoo 18 Time Off
How to Manage Allocations in Odoo 18 Time OffHow to Manage Allocations in Odoo 18 Time Off
How to Manage Allocations in Odoo 18 Time Off
Celine George
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdfপ্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
Pragya - UEM Kolkata Quiz Club
 
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
Quiz Club of PSG College of Arts & Science
 
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptxRai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
LDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-inLDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-in
LDM & Mia eStudios
 
Dashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo SlidesDashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo Slides
Celine George
 
State institute of educational technology
State institute of educational technologyState institute of educational technology
State institute of educational technology
vp5806484
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATIONTHE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
PROF. PAUL ALLIEU KAMARA
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
Quiz Club of PSG College of Arts & Science
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
How to Manage Allocations in Odoo 18 Time Off
How to Manage Allocations in Odoo 18 Time OffHow to Manage Allocations in Odoo 18 Time Off
How to Manage Allocations in Odoo 18 Time Off
Celine George
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdfপ্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
Pragya - UEM Kolkata Quiz Club
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
LDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-inLDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-in
LDM & Mia eStudios
 
Dashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo SlidesDashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo Slides
Celine George
 
State institute of educational technology
State institute of educational technologyState institute of educational technology
State institute of educational technology
vp5806484
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATIONTHE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
PROF. PAUL ALLIEU KAMARA
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 

Web Application Development using PHP Chapter 1

  • 1. CN5109 WEB APPLICATION DEVELOPMENT Chapter 1 Introduction to Server-Side Development with PHP
  • 2. What is Server-Side Development? • The basic hosting of your files is achieved through a web server. • Server-side development is much more than web hosting: it involves the use of a programming technology like PHP or ASP to create scripts that dynamically generate content. • Server-side scripting is a method of designing websites so that the process or user request is run on the originating server. • Server-side scripts provide an interface to the user and are used to limit access to proprietary data and help keep control of the script source code.
  • 3. What is Server-Side Development?
  • 4. Server-Side Scripting Examples • ActiveVFP • ASP • C • DC • Java • JavaScript (using Server-side JavaScript (SSJS) e.g., node.js) • Perl • PHP • Python • R • Ruby
  • 5. Client-side vs. Server-side Scripting Client-side Environment • The client-side environment used to run scripts is usually a browser. • The processing takes place on the end users computer. • The source code is transferred from the web server to the users computer over the internet and run directly in the browser. • The scripting language needs to be enabled on the client computer. • Sometimes if a user is conscious of security risks they may switch the scripting facility off. • When this is the case a message usually pops up to alert the user when script is attempting to run.
  • 6. Client-side vs. Server-side Scripting Server-side Environment • The server-side environment that runs a scripting language is a web server. • A user's request is fulfilled by running a script directly on the web server to generate dynamic HTML pages. • This HTML is then sent to the client browser. • It is usually used to provide interactive web sites that interface to databases or other data stores on the server. • This is different from client-side scripting where scripts are run by the viewing web browser, usually in JavaScript. • The primary advantage to server-side scripting is the ability to highly customize the response based on the user's requirements, access rights, or queries into data stores.
  • 7. Client-side vs. Server-side Scripting 1. Client page request 2. Decision making based on requested page code content 3. HTML output returned to browser
  • 8. Introduction to PHP • Created by Rasmus Lerdorf in 1994 and publicly released June 8, 1995 • PHP, which is short for PHP: Hypertext Preprocessor, is a server-side interpreted scripting language. • It was designed for creating dynamic web pages and web pages that effectively work with databases. • Files that include PHP code on a web server may have any file extension, but most commonly they end in .PHP, .PHP3, or .PHTML. • A PHP file can be created and the contents can be viewed by using a programming code editing program, such as Dreamweaver or Notepad++.
  • 9. Common Use of PHP • 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
  • 10. Advantages of PHP • PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.) • PHP is compatible with almost all servers used today (Apache, IIS, etc.) • PHP supports a wide range of databases • PHP is free. • PHP is easy to learn and runs efficiently on the server side
  • 11. PHP - Environment Setup • In order to develop and run PHP Web pages three vital components need to be installed on your computer system. • Web Server − PHP will work with virtually all Web Server software, including Microsoft's Internet Information Server (IIS) but then most often used is freely available Apache Server. • Database − PHP will work with virtually all database software, including Oracle and Sybase but most commonly used is freely available MySQL database. • PHP Parser − In order to process PHP script instructions a parser must be installed to generate HTML output that can be sent to the Web Browser.
  • 12. Quiz 1. Define Server Scripting Language 2. Give any four examples of Server Scripting Language 3. Discuss any four common use of PHP. 4. Discuss any four advantages of PHP.
  • 13. PHP Installation • To start using PHP, you can: • Find a web host with PHP and MySQL support • Install a web server on your own PC, and then install PHP and MySQL • If your server has activated support for PHP you do not need to do anything. • Just create some .php files, place them in your web directory, and the server will automatically parse them for you. • You do not need to compile anything or install any extra tools. • Because PHP is free, most web hosts offer PHP support.
  • 14. PHP Installation • However, if your server does not support PHP, you must: • install a web server (XAMPP, WAMP) • install PHP • install a database, such as MySQL
  • 15. Write PHP Online • Write PHP Online is an online code editor which helps you to write and test run/execute your php code online from your browser. • This is one of the simple and powerfull online php code editor tool available on the internet. • Write PHP Online supports all PHP functionalities and it runs using PHP version 7. http://www.writephponline.com/
  • 16. Write PHP Online 1. Write the PHP Code. 2. Click the “Run Code” button to see the output.
  • 17. PHP Syntax • A PHP script is executed on the server, and the plain HTML result is sent back to the browser. • A PHP script can be placed anywhere in the document. • A PHP script starts with <?php and ends with ?>. • PHP statements are terminated by a semicolon (;) • The default file extension for PHP files is ".php". • A PHP file normally contains HTML tags, and some PHP scripting code.
  • 18. PHP Syntax • Example <?php echo "Hello World!"; ?> Output:
  • 19. PHP in HTML • PHP is designed to interact with HTML and PHP scripts can be included in an HTML page without a problem. • In an HTML page, PHP code is enclosed within special PHP tags. <html> <body> <?php echo "Hello World!"; ?> </body> </html>
  • 20. HTML in PHP • To write HTML code in PHP file, you need to use Echo or Print statement. <?php echo “Hello World”; echo “<h1> Hello World</h1>”; ?> Output:
  • 21. Echo/ Print Statement • Used to output data to the screen. • The echo statement can be used with or without parentheses: echo or echo(). <?php echo "Hello world!"; echo 123; ?> Output:
  • 22. Echo / Print Statement • Using HTML tags in PHP: <?php echo “Hello”; echo “<br>”; echo “World”; ?> <?php echo “Hello <br> World”; ?>
  • 23. Try This <?php echo "<table border=1 width=500>"; echo "<tr>"; echo "<td>1</td><td>2</td>"; echo "</tr>"; echo "<tr>"; echo "<td>3</td><td>4</td>"; echo "</tr>"; echo "</table>"; ?> Output:
  • 24. Quiz Write a PHP code to display the following outputs: a. Welcome to FTMS College b. University of East London c. CN5109 Web Application Development
  • 25. Variables • Variables are "containers" for storing information. • In PHP, a variable starts with the $ sign, followed by the name of the variable Note: When you assign a text value to a variable, put quotes around the value. Note: Unlike other programming languages, PHP has no command for declaring a variable. It is created the moment you first assign a value to it. $txt = "Hello world!"; $x = 5; $y = 10.5;
  • 26. 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)
  • 27. Quiz Determine whether these variable names are valid or not valid. a. text b. $txt1 c. $1txt d. $txt 1 e. $txt#1 f. $txt_1
  • 28. Comments in PHP • A comment in PHP code is a line that is not read/executed as part of the program. Its only purpose is to be read by someone who is looking at the code. • Comments can be used to: • Let others understand what you are doing • Remind yourself of what you did - Most programmers have experienced coming back to their own work a year or two later and having to re-figure out what they did. Comments can remind you of what you were thinking when you wrote the code
  • 29. Comments in PHP <?php // This is a single-line comment # This is also a single-line comment /* This is a multiple-lines comment block that spans over multiple lines */ echo “This is not a comment”; ?>
  • 30. Data Types • Variables can store data of different types, and different data types can do different things. • Data types are declarations for variables. This determines the type and size of data associated with variables. • PHP supports the following data types: • String • Integer • Float (floating point numbers - also called double) • Boolean • Array • NULL
  • 31. Data Types - String • A string is a sequence of characters, like "Hello world!". • A string can be any text inside quotes. <?php $x = "Hello world!"; $y = “Hi There!”; echo $x; echo "<br>"; echo $y; ?>
  • 32. Data Types - Integer • An integer data type is a non-decimal number between - 2,147,483,648 and 2,147,483,647. • Rules for integers: • An integer must have at least one digit • An integer must not have a decimal point • An integer can be either positive or negative • Integers can be specified in three formats: decimal (10-based), hexadecimal (16-based - prefixed with 0x) or octal (8-based - prefixed with 0) <?php $x = 5985; echo $x; ?>
  • 33. Data Types - Float • A float (floating point number) is a number with a decimal point or a number in exponential form. • In the following example $x is a float. • The PHP var_dump() function returns the data type and value. <?php $x = 10.365; echo $x; ?>
  • 34. Data Types - Boolean • A Boolean represents two possible states: TRUE or FALSE. • Booleans are often used in conditional testing. $x = true; $y = false; echo $x;
  • 35. Data Types - Array • An array stores multiple values in one single variable. • In the following example $cars is an array. <?php $cars = array("Volvo","BMW","Toyota","Honda"); echo $cars[0],"<br>"; echo $cars[1],"<br>"; echo $cars[2],"<br>"; echo $cars[3],"<br>"; ?>
  • 36. Data Types - Null • Null is a special data type which can have only one value: NULL. • A variable of data type NULL is a variable that has no value assigned to it. • Tip: If a variable is created without a value, it is automatically assigned a value of NULL. • Variables can also be emptied by setting the value to NULL <?php $x = null; echo $x; ?>
  • 37. Quiz Identify the data type of the following data: a. “Cyberjaya” b. 1.35 c. 50 d. True e. A f. “False” g. h. 1, 2, 4, 8 i. “25”
  • 38. Operator • Operators are used to perform mathematical operations on variables and values. • PHP divides the operators in the following groups: • Arithmetic operators • Assignment operators • Comparison operators • Increment/Decrement operators • Logical operators • String operators • Array operators
  • 39. Arithmetic Operators • Arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc. Operation Name Example Result + Addition $x + $y Sum of $x and $y - Subtraction $x - $y Difference of $x and $y * Multiplication $x * $y Product of $x and $y / Division $x / $y Quotient of $x and $y % Modulus $x % $y Remainder of $x divided by $y
  • 40. Arithmetic Operators • Example $x = 10; $y = 5; echo $x + $y,"<br>"; echo $x - $y,"<br>"; echo $x * $y,"<br>"; echo $x / $y,"<br>"; echo $x % $y,"<br>"; Output:
  • 41. Comparison Operators • The PHP comparison operators are used to compare two values (number or string). Operator Name Example Result == Equal $x == $y Returns true if $x is equal to $y != Not equal $x != $y Returns true if $x is not equal to $y <> Not equal $x <> $y Returns true if $x is not equal to $y > Greater than $x > $y Returns true if $x is greater than $y < Less than $x < $y Returns true if $x is less than $y >= Greater than or equal to $x >= $y Returns true if $x is greater than or equal to $y <= Less than or equal to $x <= $y Returns true if $x is less than or equal to $y
  • 42. Comparison Operators • Example $x = 10; $y = 5; echo $x == $y,"<br>"; echo $x <> $y,"<br>"; echo $x < $y,"<br>"; echo $x > $y,"<br>"; Output:
  • 43. Increment /Decrement Operators • Increment operators are used to increment a variable's value. • Decrement operators are used to decrement a variable's value. Operator Name Description ++$x Pre-increment Increments $x by one, then returns $x $x++ Post-increment Returns $x, then increments $x by one --$x Pre-decrement Decrements $x by one, then returns $x $x-- Post-decrement Returns $x, then decrements $x by one
  • 44. Increment /Decrement Operators • Example $x = 10; echo $x ,"<br>"; echo ++$x ,"<br>"; echo $x ,"<br>"; echo $x++ ,"<br>"; Output:
  • 45. Logical Operators • Example Operator Name Example Result and And $x and $y True if both $x and $y are true or Or $x or $y True if either $x or $y is true xor Xor $x xor $y True if either $x or $y is true, but not both && And $x && $y True if both $x and $y are true || Or $x || $y True if either $x or $y is true ! Not !$x True if $x is not true
  • 46. Logical Operators • Example $x = 100; $y = 50; if ($x == 100 and $y == 50) { echo "Hello world!"; } Output:
  • 47. Quiz Solve the following equations: Given $x = 10 and $y = 5 a. $x + $x + $y b. $x - $y + $x c. $x + $y * $x d. $x / $y + $x e. $x > $y f. $y != $x g. ++$x h. $y--