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

PHP (Lec) Sa1

This document provides an introduction to PHP web programming. It discusses PHP's history from its initial creation in 1994 to the current version PHP 7. It outlines the objectives of learning PHP and describes the software required, including web servers, databases, code editors and more. It also demonstrates how to run PHP scripts using XAMPP and provides examples of PHP syntax for variables, outputting data, comments and datatypes.

Uploaded by

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

PHP (Lec) Sa1

This document provides an introduction to PHP web programming. It discusses PHP's history from its initial creation in 1994 to the current version PHP 7. It outlines the objectives of learning PHP and describes the software required, including web servers, databases, code editors and more. It also demonstrates how to run PHP scripts using XAMPP and provides examples of PHP syntax for variables, outputting data, comments and datatypes.

Uploaded by

Angelo Payod
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 132

Applications Development and

Emerging Technologies
MODULE 1
Web Architecture, Tools, and
Introduction to PHP
An introduction to PHP web programming

Objectives
• To understand the history of PHP
• To know the advantages of PHP as a server side scripting
language
• To know what are the software's needed in developing web
application using PHP.
• To run PHP application on a web browser.
• To know the basic syntax of PHP for outputting to browser.
• To know the datatypes that are available on PHP and on
how these datatypes are being used.
• To know some predefined type function for data
manipulation.
• To know the proper casting values of a given variables.
An introduction to PHP web programming

HISTORY
• 1994/1995 (PHP 1.0)
• Developed by Rasmus Lerdorf
• To know how many visitors were reading his online
resume based on PERL/CGI script
• Personal Home Page (PHP)
• 1997 (PHP 2.0)
• PHP is based on C rather than PERL
• Personal Home Page/Form Interpreter
• 1998 (PHP 3.0)
• 50,000 users were using PHP to enhance their Web pages
• Developers joined Lerdorf
• 1999 (PHP 4.0)
• With core developers Zeev Suraski and Andi Gutmans
• PHP makes the most popular scripting language with
morethan one million user base by Netcraff
An introduction to PHP web programming

HISTORY (Con’t.)
• Hundreds of functions being added
• Dubbed the Zend scripting engine
• May 22, 2000 (PHP 4.0)
• PHP: Hypertext Preprocessor (recursive acronym)
• 3.6 million domain PHP installed
• Enterprise development
• Improved resource handling (scalability)
• Object-oriented support (Classes and Objects)
• Native session-handling support (session)
• Encryption (encryption algoritms)
• ISAPI Support (for IIS)
• Native COM/DOM (Windows applications)
• Native Java Support: (binding to java objects)
• PERL Compatible Regular Expressions
• New features, power, and scalabilty
An introduction to PHP web programming

HISTORY (Con’t.)
• PHP 5 (July 13, 2004)
• Vastly improved object-oriented capabilities: OOP
improvement
• Try/catch exception handling
• Improved XML and Web Services support (Simple XML
Support, using SOAP)
• Native support for SQLite
• Installed on 19 million domains
• 54 percent on all Apache module
• PHP 6 (2007 not yet released)
• Unicode Support (Native Unicode support for multilingual
applications
• Security improvements
• New language features and constructs (64-bit type integer,
foreach looping)
http://en.wikipedia.org/wiki/PHP
An introduction to PHP web programming

HISTORY (Con’t.)
PHP Key categories
• Practicality
• PHP is a loosely type language (no explicitly create,
typecast, or destroy a variable)
• Power
• More libraries and thousands of functions
• Possibility
• Native support is offered for more than 25 database
products, including Adabas D, dBase, Empress,
FilePro, FrontBase, Hyperwave, IBM DB2, Informix,
Ingres, InterBase, mSQL, Microsoft SQL Server,
MySQL, Oracle, Ovrimos, PostgreSQL, Solid, Sybase,
Unix dbm, and Velocis.
• Both structured and Object Oriented approach
• Price
• Free of charge
An introduction to PHP web programming

Web Architecture Page Request

html
Internet

scripts

database
An introduction to PHP web programming

Software Requirements
Operating System: Linux
An introduction to PHP web programming

Software Requirements
Operating System: Windows
An introduction to PHP web programming

Software Requirements
Operating System: Mac
Cheetah

Panther

Puma

Jaguar Tiger

Leopard Snow leopard


Lion
An introduction to PHP web programming

Software Requirements
Internet browser

Opera
Mozilla
Internet Safari
Google Firefox
Chrome Explorer

Deepnet
Rockmelt Explorer Avant
Maxthon Browser
SeaMonkey
An introduction to PHP web programming

Software Requirements
Web Server

Apache

Google Web Server (GWS)


An introduction to PHP web programming

Software Requirements
Server side scripting language

Java Active Server Pages


(JavaServer Pages: JSP) (ASP)
Ruby (Ruby on Rails)

Python
PERL CGI
(Django)
An introduction to PHP web programming

Software Requirements
Database

Oracle
An introduction to PHP web programming

Software Requirements
Code editor

Bluefish

Dreamweaver
An introduction to PHP web programming

Software Requirements
Other
An introduction to PHP web programming

Software Requirements
Other
Operating System
Windows 7 / Windows 8

Web Server
Apache

Language Script XAMPP / WAMP


PHP

Database
MySQL

Code Editor
Notepad++ / Eclipse / Netbeans / Dreamweaver
An introduction to PHP web programming

Running PHP Scripts


XAMPP
1. Download XAMPP
http://www.apachefriends.org/en/xampp.html
2. Install XAMPP
3. Run XAMPP Control
• c:\xampp (by default)
• Start the Apache and MySQL(for database) Service
4. Create a folder under c:\xampp\htdocs\ (by default)
Note: All php files must be save on that folder
5. Test PHP script sample file.
5. Open some internet browser
6. Type localhost/[folder name] (by default)
7. Select file from the directory list (if there’s
An introduction to PHP web programming

Running PHP Scripts


All php scripts must enclosed
with
<?php … ?> (standard tag)
<? … ?> (short open tag)
<script language=“php”>
….
</script> (script tag)
<% … %> (asp style tag)

OUTPUT:
An introduction to PHP web programming

Running PHP Scripts


opening tag for php script Statement terminator

echo – is a language construct


that use to output one or more
closing tag for php script string.

print – is a function also use for


outputting strings.
An introduction to PHP web programming

PHP Comments
An introduction to PHP web programming

PHP Variables
• Variables are used as a container for values that can be used and
manipulate PHP scripts.
• Variables in PHP must begin with a $ symbol.
• Variable might contain a string, numbers, arrays and objects.
• Setting the identifier for a variable must follow some rules.
1. First character can be ‘_’ or a letter.
2. It can only contain alpha-numeric characters and underscore
(a-z,A-Z,0-9,_).
3. Don’t use white space in naming a variable.
• Variables in PHP is not explicitly declared
• Variables are case sensitive

Example
$age, $firstName, $totalSalary, $_myValue,
$str1, $tmp01
An introduction to PHP web programming

Using ‘ ‘ (pair single quote), “ “ (pair double


quotes) and . (dot character) PHP
1. Strings inside the ‘ and ‘ are interpreted as literal strings
1. To display a ‘ character (single quote) as string use the
escape character \ (backslash).
2. Strings inside the “ and “ are interpreted as literal strings with
some exceptions
1. $ inside “ and “ are interpreted as variables thus it will
display the value rather than the string that starts with $.
2. To display the string that starts with $ and to display the
double quote as string use the escape character \
(backslash).
3. To concatenate string values use the . (dot or period)
character thus “abc“.”def” yields to a value “abcdef”
An introduction to PHP web programming

Using ‘ ‘ (pair single quote), “ “ (pair double


quotes) and . (dot character) PHP
Example: Output:
An introduction to PHP web programming

Outputting Data
echo syntax
void echo(string argument1[,…string argumentN]

print syntax
int print(argument)

printf syntax
boolean printf(string format [, mixed args])
An introduction to PHP web programming

Outputting Data
Example:

Output:
An introduction to PHP web programming

Commonly Used Type Specifiers for printf function

Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.100
An introduction to PHP web programming

PHP Datatypes

Datatypes
is the generic name assigned to any data sharing a common set of
characteristics.

Scalar Datatypes
Capable of containing a single item of information
(Boolean, Integer, Float (float, double or real numbers), String)

Compound Datatypes
allow for multiple items of the same type to be aggregated under a
single representative entity.
(Array and Objects)
An introduction to PHP web programming

Scalar Datatypes
Eample:
An introduction to PHP web programming

Compound Datatypes

Example:

Output:

Output:
An introduction to PHP web programming

PHP Type Casting Operators

Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.105
An introduction to PHP web programming

PHP Type Casting Operators

Example: Output:
An introduction to PHP web programming

PHP Type Juggling

Example: Output:
An introduction to PHP web programming

Predefined Type Functions


gettype() function
returns the type of the variable. Possible return values are
integer, double, boolean, string, array, object, resource,
unknown types.
prototype:
string gettype(mixed var)

settype() function
converts a given variable to a specific type.
prototype:
boolean settype(mixed var, string type)

Predefined Type Identifier Functions


is_array(), is_bool(), is_float(), is_integer(),
is_null(), is_numeric(), is_object(), is_resource(),
is_scalar(), and is_string()
An introduction to PHP web programming

Type Functions

Example:

Output:
An introduction to PHP web programming

Summary
• PHP was developed originally by Rasmus Lerdorf
• Seev Suraski and Andi Gutsman were the one who contribute most
in PHP development.
• PHP key categories are practicality, power, possibility, and price.
• PHP is a embedded language that is commonly embedded on
HTML
• PHP is a server-side scripting language that runs its application on a
Web server.
• Much of the PHP syntax were derive from C programming
Language.
• You can integrate database easily in PHP.
• Standard PHP script are enclosed by <?php and ?> tags.
• Each statement in PHP must be terminated with a semi-colon(;).
• All variable in PHP must have a dollar ($) character before its
identifier.
An introduction to PHP web programming

Summary (Continue)
• PHP variables are not explicitly declared.
• You can use echo, print, or printf function for outputting strings to
internet browser.
• You can enclosed string using a pair of single quote or pair of
double quote.
• String inside a pair of single quote interpreted as literal except for
the single quote itself.
• String inside a pair of double quote interpreted as literal with some
exception like using dollar character.
• To explicitly display the character on the internet browser use
backslash (\) character like \$, \’, \” and etc.
• Datatypes in PHP can be categorized as scalar or compound
datatypes.
• You can explicitly change the type of a variable in PHP.
• PHP support some predefined type function that can be used in
manipulating type variables.
Applications Development and
Emerging Technologies
MODULE 2
PHP Operators and Control
Structures
PHP Operators and Control Structures

Objectives
• To understand the different types of operators that are
available on PHP.
• To know what is operator precedence and operator
associativity in PHP.
• To ensure that programs expression are logically correct by
using the correct referencing values of its precedence.
• To use escape sequence properly in the program.
• To know the different approach of control structures.
• To know the fundamentals syntax for conditional and
looping structures.
• To properly use the compound expression using the logical
operators.
• To know the rules of break, continue, and goto statements.
• To see some alternative enclosure for control structures.
PHP Operators and Control Structures

Operators
An operator is a symbol that specifies a particular action in an expression

Operator Precedence, Associativity, and Pupose


PHP Operators and Control Structures

Operator Precedence, Associativity, and Pupose

Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.124
PHP Operators and Control Structures

Operator Precedence
is a characteristic of operators that determines the order in which they
evaluate the operands surrounding them.

Output:
PHP Operators and Control Structures

Operator Associativity
is a characteristic of an operator specifies how operations of the same
precedence are evaluated as they are executed.

Output:

Example:
PHP Operators and Control Structures

Arithmetic Operator

Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.124

Assignment Operator

Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.126
PHP Operators and Control Structures

Increment and Decrement Operator

Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.127

Example: Output:
PHP Operators and Control Structures

Comparison Operator

Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.129

Example: Output:
PHP Operators and Control Structures

Logical Operator

Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.128
Equality Operator

Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.129
PHP Operators and Control Structures

Bitwise Operator

Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.130

Example: Output:
PHP Operators and Control Structures

Escape Sequences

Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.132
PHP Operators and Control Structures

PHP Control Structures: Conditional Statements

if statement
syntax: elseif statement
if(expression) { syntax:
statement… if(expression) {
} statement…
}
else statement elseif(expression) {
syntax: statement…
if(expression) { } else {
statement… statement…
} else { }
statement
}
PHP Operators and Control Structures

PHP Control Structures: Conditional Statements


Example:
Output:
PHP Operators and Control Structures

PHP Control Structures: Conditional Statements


Nested if…else

Output:
Example:
PHP Operators and Control Structures

PHP Control Structures: Conditional Statements


Compound expression using logical operators

Output:
Example:
PHP Operators and Control Structures

PHP Control Structures: Conditional Statements


switch statement
syntax:
switch($category){
case opt1:
statement…
break;
case opt2:
statement…
break;
case opt3:
statement…
break;

default:
statement…
}
PHP Operators and Control Structures

PHP Control Structures: Conditional Statements


Switch Statement

Example: Output:
PHP Operators and Control Structures

PHP Control Structures: Looping Statements

while statement for statement


syntax: syntax:
while(expression){ for(expr1;expr2;expr3)
statement… {
} statement…
}
do … while statement
syntax:
do{
statement…
}while(expression);
PHP Operators and Control Structures

PHP Control Structures: Looping Statements

Example: Output:
PHP Operators and Control Structures

PHP Control Structures: break, continue,


and goto statement

break
break statement is placed within the code of a loop to cause
the program to break out of the loop statement.

continue
continue statement causes execution of the current loop
iteration to end and commence at the beginning of the next iteration.

goto … label:
goto statement is used to jump to other section of the
program to support labels.
PHP Operators and Control Structures

PHP Control Structures: break, continue,


and goto statement

Example:
Output:
PHP Operators and Control Structures

PHP Control Structures: alternative enclosure syntax

Involves replacing the opening bracket with a colon(:) and


replacing the closing bracket with endif;, endwhile;,endfor;,
endswitch

Example: Output:
PHP Operators and Control Structures

Summary
• Simplifying expression needs to follow a general precedence set by
PHP scripts.
• An operator specifies a particular action in a given expression.
• Available PHP operators are arithmetic, conditional, assignment,
logical and bitwise operator.
• Operator precedence characteristics determines the order in which
they evaluate the operands surrounding them.
• Operator associativity characteristic specifies how operations of the
same precedence are evaluated as they are executed.
• Post increment or decrement always execute the statement first
before incrementing or decrementing the value of a given variable.
• Pre increment or decrement always increment or decrement its
variable value before executing the statement.
• Escape sequence has its own special task in executing the string
as an output.
PHP Operators and Control Structures

Summary (Continue)
• Conditional statements are statement the will execute statement
inside a block if a given condition is true
• Use compound expression to minimize the process of coding using
nested if statement.
• break statement caused the program to break if used.
• continue statement end the current loop and continue to next
iteration.
• goto statement used to jump to other section of the program.
• Alternative enclosure syntax is available for if, while, for, foreach,
and switch control.
Applications Development and
Emerging Technologies
MODULE 1
Web Architecture, Tools, and
Introduction to PHP
An introduction to PHP web programming

Objectives
• To understand the history of PHP
• To know the advantages of PHP as a server side scripting
language
• To know what are the software's needed in developing web
application using PHP.
• To run PHP application on a web browser.
• To know the basic syntax of PHP for outputting to browser.
• To know the datatypes that are available on PHP and on
how these datatypes are being used.
• To know some predefined type function for data
manipulation.
• To know the proper casting values of a given variables.
An introduction to PHP web programming

HISTORY
• 1994/1995 (PHP 1.0)
• Developed by Rasmus Lerdorf
• To know how many visitors were reading his online
resume based on PERL/CGI script
• Personal Home Page (PHP)
• 1997 (PHP 2.0)
• PHP is based on C rather than PERL
• Personal Home Page/Form Interpreter
• 1998 (PHP 3.0)
• 50,000 users were using PHP to enhance their Web pages
• Developers joined Lerdorf
• 1999 (PHP 4.0)
• With core developers Zeev Suraski and Andi Gutmans
• PHP makes the most popular scripting language with
morethan one million user base by Netcraff
An introduction to PHP web programming

HISTORY (Con’t.)
• Hundreds of functions being added
• Dubbed the Zend scripting engine
• May 22, 2000 (PHP 4.0)
• PHP: Hypertext Preprocessor (recursive acronym)
• 3.6 million domain PHP installed
• Enterprise development
• Improved resource handling (scalability)
• Object-oriented support (Classes and Objects)
• Native session-handling support (session)
• Encryption (encryption algoritms)
• ISAPI Support (for IIS)
• Native COM/DOM (Windows applications)
• Native Java Support: (binding to java objects)
• PERL Compatible Regular Expressions
• New features, power, and scalabilty
An introduction to PHP web programming

HISTORY (Con’t.)
• PHP 5 (July 13, 2004)
• Vastly improved object-oriented capabilities: OOP
improvement
• Try/catch exception handling
• Improved XML and Web Services support (Simple XML
Support, using SOAP)
• Native support for SQLite
• Installed on 19 million domains
• 54 percent on all Apache module
• PHP 6 (2007 not yet released)
• Unicode Support (Native Unicode support for multilingual
applications
• Security improvements
• New language features and constructs (64-bit type integer,
foreach looping)
http://en.wikipedia.org/wiki/PHP
An introduction to PHP web programming

HISTORY (Con’t.)
PHP Key categories
• Practicality
• PHP is a loosely type language (no explicitly create,
typecast, or destroy a variable)
• Power
• More libraries and thousands of functions
• Possibility
• Native support is offered for more than 25 database
products, including Adabas D, dBase, Empress,
FilePro, FrontBase, Hyperwave, IBM DB2, Informix,
Ingres, InterBase, mSQL, Microsoft SQL Server,
MySQL, Oracle, Ovrimos, PostgreSQL, Solid, Sybase,
Unix dbm, and Velocis.
• Both structured and Object Oriented approach
• Price
• Free of charge
An introduction to PHP web programming

Web Architecture Page Request

html
Internet

scripts

database
An introduction to PHP web programming

Software Requirements
Operating System: Linux
An introduction to PHP web programming

Software Requirements
Operating System: Windows
An introduction to PHP web programming

Software Requirements
Operating System: Mac
Cheetah

Panther

Puma

Jaguar Tiger

Leopard Snow leopard


Lion
An introduction to PHP web programming

Software Requirements
Internet browser

Opera
Mozilla
Internet Safari
Google Firefox
Chrome Explorer

Deepnet
Rockmelt Explorer Avant
Maxthon Browser
SeaMonkey
An introduction to PHP web programming

Software Requirements
Web Server

Apache

Google Web Server (GWS)


An introduction to PHP web programming

Software Requirements
Server side scripting language

Java Active Server Pages


(JavaServer Pages: JSP) (ASP)
Ruby (Ruby on Rails)

Python
PERL CGI
(Django)
An introduction to PHP web programming

Software Requirements
Database

Oracle
An introduction to PHP web programming

Software Requirements
Code editor

Bluefish

Dreamweaver
An introduction to PHP web programming

Software Requirements
Other
An introduction to PHP web programming

Software Requirements
Other
Operating System
Windows 7 / Windows 8

Web Server
Apache

Language Script XAMPP / WAMP


PHP

Database
MySQL

Code Editor
Notepad++ / Eclipse / Netbeans / Dreamweaver
An introduction to PHP web programming

Running PHP Scripts


XAMPP
1. Download XAMPP
http://www.apachefriends.org/en/xampp.html
2. Install XAMPP
3. Run XAMPP Control
• c:\xampp (by default)
• Start the Apache and MySQL(for database) Service
4. Create a folder under c:\xampp\htdocs\ (by default)
Note: All php files must be save on that folder
5. Test PHP script sample file.
5. Open some internet browser
6. Type localhost/[folder name] (by default)
7. Select file from the directory list (if there’s
An introduction to PHP web programming

Running PHP Scripts


All php scripts must enclosed
with
<?php … ?> (standard tag)
<? … ?> (short open tag)
<script language=“php”>
….
</script> (script tag)
<% … %> (asp style tag)

OUTPUT:
An introduction to PHP web programming

Running PHP Scripts


opening tag for php script Statement terminator

echo – is a language construct


that use to output one or more
closing tag for php script string.

print – is a function also use for


outputting strings.
An introduction to PHP web programming

PHP Comments
An introduction to PHP web programming

PHP Variables
• Variables are used as a container for values that can be used and
manipulate PHP scripts.
• Variables in PHP must begin with a $ symbol.
• Variable might contain a string, numbers, arrays and objects.
• Setting the identifier for a variable must follow some rules.
1. First character can be ‘_’ or a letter.
2. It can only contain alpha-numeric characters and underscore
(a-z,A-Z,0-9,_).
3. Don’t use white space in naming a variable.
• Variables in PHP is not explicitly declared
• Variables are case sensitive

Example
$age, $firstName, $totalSalary, $_myValue,
$str1, $tmp01
An introduction to PHP web programming

Using ‘ ‘ (pair single quote), “ “ (pair double


quotes) and . (dot character) PHP
1. Strings inside the ‘ and ‘ are interpreted as literal strings
1. To display a ‘ character (single quote) as string use the
escape character \ (backslash).
2. Strings inside the “ and “ are interpreted as literal strings with
some exceptions
1. $ inside “ and “ are interpreted as variables thus it will
display the value rather than the string that starts with $.
2. To display the string that starts with $ and to display the
double quote as string use the escape character \
(backslash).
3. To concatenate string values use the . (dot or period)
character thus “abc“.”def” yields to a value “abcdef”
An introduction to PHP web programming

Using ‘ ‘ (pair single quote), “ “ (pair double


quotes) and . (dot character) PHP
Example: Output:
An introduction to PHP web programming

Outputting Data
echo syntax
void echo(string argument1[,…string argumentN]

print syntax
int print(argument)

printf syntax
boolean printf(string format [, mixed args])
An introduction to PHP web programming

Outputting Data
Example:

Output:
An introduction to PHP web programming

Commonly Used Type Specifiers for printf function

Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.100
An introduction to PHP web programming

PHP Datatypes

Datatypes
is the generic name assigned to any data sharing a common set of
characteristics.

Scalar Datatypes
Capable of containing a single item of information
(Boolean, Integer, Float (float, double or real numbers), String)

Compound Datatypes
allow for multiple items of the same type to be aggregated under a
single representative entity.
(Array and Objects)
An introduction to PHP web programming

Scalar Datatypes
Eample:
An introduction to PHP web programming

Compound Datatypes

Example:

Output:

Output:
An introduction to PHP web programming

PHP Type Casting Operators

Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.105
An introduction to PHP web programming

PHP Type Casting Operators

Example: Output:
An introduction to PHP web programming

PHP Type Juggling

Example: Output:
An introduction to PHP web programming

Predefined Type Functions


gettype() function
returns the type of the variable. Possible return values are
integer, double, boolean, string, array, object, resource,
unknown types.
prototype:
string gettype(mixed var)

settype() function
converts a given variable to a specific type.
prototype:
boolean settype(mixed var, string type)

Predefined Type Identifier Functions


is_array(), is_bool(), is_float(), is_integer(),
is_null(), is_numeric(), is_object(), is_resource(),
is_scalar(), and is_string()
An introduction to PHP web programming

Type Functions

Example:

Output:
An introduction to PHP web programming

Summary
• PHP was developed originally by Rasmus Lerdorf
• Seev Suraski and Andi Gutsman were the one who contribute most
in PHP development.
• PHP key categories are practicality, power, possibility, and price.
• PHP is a embedded language that is commonly embedded on
HTML
• PHP is a server-side scripting language that runs its application on a
Web server.
• Much of the PHP syntax were derive from C programming
Language.
• You can integrate database easily in PHP.
• Standard PHP script are enclosed by <?php and ?> tags.
• Each statement in PHP must be terminated with a semi-colon(;).
• All variable in PHP must have a dollar ($) character before its
identifier.
An introduction to PHP web programming

Summary (Continue)
• PHP variables are not explicitly declared.
• You can use echo, print, or printf function for outputting strings to
internet browser.
• You can enclosed string using a pair of single quote or pair of
double quote.
• String inside a pair of single quote interpreted as literal except for
the single quote itself.
• String inside a pair of double quote interpreted as literal with some
exception like using dollar character.
• To explicitly display the character on the internet browser use
backslash (\) character like \$, \’, \” and etc.
• Datatypes in PHP can be categorized as scalar or compound
datatypes.
• You can explicitly change the type of a variable in PHP.
• PHP support some predefined type function that can be used in
manipulating type variables.
Applications Development and
Emerging Technologies
MODULE 2
PHP Operators and Control
Structures
PHP Operators and Control Structures

Objectives
• To understand the different types of operators that are
available on PHP.
• To know what is operator precedence and operator
associativity in PHP.
• To ensure that programs expression are logically correct by
using the correct referencing values of its precedence.
• To use escape sequence properly in the program.
• To know the different approach of control structures.
• To know the fundamentals syntax for conditional and
looping structures.
• To properly use the compound expression using the logical
operators.
• To know the rules of break, continue, and goto statements.
• To see some alternative enclosure for control structures.
PHP Operators and Control Structures

Operators
An operator is a symbol that specifies a particular action in an expression

Operator Precedence, Associativity, and Pupose


PHP Operators and Control Structures

Operator Precedence, Associativity, and Pupose

Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.124
PHP Operators and Control Structures

Operator Precedence
is a characteristic of operators that determines the order in which they
evaluate the operands surrounding them.

Output:
PHP Operators and Control Structures

Operator Associativity
is a characteristic of an operator specifies how operations of the same
precedence are evaluated as they are executed.

Output:

Example:
PHP Operators and Control Structures

Arithmetic Operator

Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.124

Assignment Operator

Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.126
PHP Operators and Control Structures

Increment and Decrement Operator

Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.127

Example: Output:
PHP Operators and Control Structures

Comparison Operator

Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.129

Example: Output:
PHP Operators and Control Structures

Logical Operator

Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.128
Equality Operator

Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.129
PHP Operators and Control Structures

Bitwise Operator

Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.130

Example: Output:
PHP Operators and Control Structures

Escape Sequences

Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.132
PHP Operators and Control Structures

PHP Control Structures: Conditional Statements

if statement
syntax: elseif statement
if(expression) { syntax:
statement… if(expression) {
} statement…
}
else statement elseif(expression) {
syntax: statement…
if(expression) { } else {
statement… statement…
} else { }
statement
}
PHP Operators and Control Structures

PHP Control Structures: Conditional Statements


Example:
Output:
PHP Operators and Control Structures

PHP Control Structures: Conditional Statements


Nested if…else

Output:
Example:
PHP Operators and Control Structures

PHP Control Structures: Conditional Statements


Compound expression using logical operators

Output:
Example:
PHP Operators and Control Structures

PHP Control Structures: Conditional Statements


switch statement
syntax:
switch($category){
case opt1:
statement…
break;
case opt2:
statement…
break;
case opt3:
statement…
break;

default:
statement…
}
PHP Operators and Control Structures

PHP Control Structures: Conditional Statements


Switch Statement

Example: Output:
PHP Operators and Control Structures

PHP Control Structures: Looping Statements

while statement for statement


syntax: syntax:
while(expression){ for(expr1;expr2;expr3)
statement… {
} statement…
}
do … while statement
syntax:
do{
statement…
}while(expression);
PHP Operators and Control Structures

PHP Control Structures: Looping Statements

Example: Output:
PHP Operators and Control Structures

PHP Control Structures: break, continue,


and goto statement

break
break statement is placed within the code of a loop to cause
the program to break out of the loop statement.

continue
continue statement causes execution of the current loop
iteration to end and commence at the beginning of the next iteration.

goto … label:
goto statement is used to jump to other section of the
program to support labels.
PHP Operators and Control Structures

PHP Control Structures: break, continue,


and goto statement

Example:
Output:
PHP Operators and Control Structures

PHP Control Structures: alternative enclosure syntax

Involves replacing the opening bracket with a colon(:) and


replacing the closing bracket with endif;, endwhile;,endfor;,
endswitch

Example: Output:
PHP Operators and Control Structures

Summary
• Simplifying expression needs to follow a general precedence set by
PHP scripts.
• An operator specifies a particular action in a given expression.
• Available PHP operators are arithmetic, conditional, assignment,
logical and bitwise operator.
• Operator precedence characteristics determines the order in which
they evaluate the operands surrounding them.
• Operator associativity characteristic specifies how operations of the
same precedence are evaluated as they are executed.
• Post increment or decrement always execute the statement first
before incrementing or decrementing the value of a given variable.
• Pre increment or decrement always increment or decrement its
variable value before executing the statement.
• Escape sequence has its own special task in executing the string
as an output.
PHP Operators and Control Structures

Summary (Continue)
• Conditional statements are statement the will execute statement
inside a block if a given condition is true
• Use compound expression to minimize the process of coding using
nested if statement.
• break statement caused the program to break if used.
• continue statement end the current loop and continue to next
iteration.
• goto statement used to jump to other section of the program.
• Alternative enclosure syntax is available for if, while, for, foreach,
and switch control.

You might also like