SlideShare a Scribd company logo
PHP
afm -INFO2301S1Y1314
THE BUILDING BLOCKS
Contents
 Anatomy
 Literals
 DataTypes
 Variables
 Constant
afm -INFO2301S1Y1314
 A PHP script is a web file with .php extension and is consisting of
text, HTML, and PHP instructions interspersed/intertwined throughout
the file.
 The PHP instructions are contained within two php tags; <?php
…the opening tag & the closing tag.. ?>.
 The content between these two tags is interpreted by the Zend
engine (PHP module/the interpreter) and converted to regular text &
HTML before being sent back to the requesting browser.
 This way browser wont see any of the PHP content of PHP
scripting in the file it requested.
 Consider the following exercise, and have a look at source code
on the browser .
Anatomy
afm -INFO2301S1Y1314
 <html>
<body>
<?php $string = ‘world’;
echo “<b1> Salam to the $string.<br />“ ;
?>
</body
Four different styles of tagging PHP:
1) XML style
 <?php echo “salam world”; ?>
 a default style (no configuration needed)
 most preferred style
 blend with other XML document
2) Short style
 <? echo “salam world”; ?>
 disabled by default
 configuration needed in php.ini (short_open_tag= ‘on’)
 the simplest tag style
 follows SGML processing instructions style
 interfere with XML document
Literals
afm -INFO2301S1Y1314
Four different styles of tagging PHP:
3) script style
 < script language = “php”> echo “salam world !”; </script>
 Enabled by default (no configuration needed)
 the longest tag style
 Follows executing Javascript and VBscript style
 An alternative style if using other styles cause a
problem in HTML editor
4) ASP style
 <% echo “salam world !”; %>
 Configuration needed in php.ini (asp_tag = ‘on’)
 Disabled by default
 The ASP web developer friendly styles
 Follows ASP processing instruction style
 Interfere with XML document
Literals
afm -INFO2301S1Y1314
Tagging comments in PHP:
i. Blocked comments : example –
/* a long paragraphed comment can be addressed and
exploited within this compound. PHP scripts rendered
non-executable within these symbols */
ii. Line comments:
// a one line comment is addressed like this.
// add another double slashes to add a next line comment
Literals
afm -INFO2301S1Y1314
PHP supports four core data types:
1) Integers  whole numbers and do not contain a decimal point;
integers can be expressed in decimal (base 10), octal (base 8),
and hexadecimal (base 16), and are either positive or negative
values.
e.g. 12345 integer, 0x456fff integer in base 16(hexadecimal), 0777
integer in base 8(octal)
2) Float (also called double or reals)  fractional numbers such as
123.56 or –2.5. They must contain a decimal point or an exponent
specifier, such as 1.3e–2. The letter “e” can be either uppercase
or lower case.
e.g. 23.45 float, .234E–2 float in scientific notation, .234e+3 float
in scientific notation.
Data types
afm -INFO2301S1Y1314
PHP supports four core data types:
3) String  a sequence of characters, either as a literal constant or
as some kind of variable. Some notes on string operations ! :
a) Single quotes treat all character equally e.g. $str = ‘$sign’
b) Double quotes DO NOT treat all characters equally. e.g.
$str =“another $str”;
c) String can contain escape sequences (a single character
preceded with backlash ‘’). Backlash can be used for quoting
‘conflicting’ character. e.g. $str = ‘I can’t help you !’;
Data types
afm -INFO2301S1Y1314
PHP supports four core data types:
3) String  escape sequences (a single character preceded with
backlash ‘’).
 Other uses of escape sequences as follows
Data types
afm -INFO2301S1Y1314
PHP supports four core data types:
4) Boolean  or boolean logic, is a subset of algebra used for creating
true/false statements. Boolean expressions use the operators AND, OR,
XOR, and NOT to compare values and return a true or false result. These
boolean operators are described in the following four examples:
 x AND y - returns True if both x and y are true; returns False if either
x or y are false.
 x OR y - returns True if either x or y, or both x and y are true; returns
False only if x and y are both false.
 X OR y - returns True if only x or y is true; returns False if x and y are
both true or both false.
 NOT x - returns True if x is false (or null); returns False if x is true.
Data types
afm -INFO2301S1Y1314
PHP also supports 4 other SPECIAL data types:
1) NULL
2) ARRAY
3) OBJECT
4) RESOURCES
Data types
afm -INFO2301S1Y1314
Types of Variables in PHP
 Predefined variables
 User defined variables
 Form variables related to names in an HTML form
Variables
afm -INFO2301S1Y1314
 Predefined variables
Variables
afm -INFO2301S1Y1314
 User Defined Variables = by value
Variables
afm -INFO2301S1Y1314
Criteria :
a) A variable must have a name
 Variable name starts with a dollar sign ($), followed by a character
or a set of alphanumeric chars including underscore. e.g. $user,
$3int, $_fraction etc.
b) A variable must have value
 A variable is complete as soon as a value is assigned to it. e.g.
$user = ‘ali’; or $3int = 321; or $_fraction = 2.17; or $_bool=
FALSE etc. A variable is complete as soon as a value is assigned
to it. e.g.
c) A variable must have type
 A variable type goes by the data type it is initiated with. e.g. $user
= ‘ali’; //a string var or $3int = 321 //int variable; or $_fraction =
2.17; // float var or $_bool= FALSE etc.
d) A variable name is case sensitive
 e.g. $var and $VAR are referring to two different variables.
Displaying variable
Variables
afm -INFO2301S1Y1314
 echo “parameter” - output one or more string and all
parameters. (void echo ( string $arg1 [, string $... ] ). It can take a
comma-separated list of string arguments
 print “arg” - Outputs a string. (int print (string $arg).
Example:
$name = “Omar”; $state = “Selangor”;$salary = 10000;
echo $name, $state, $salary;
print $name;
print $name.$state.$salary;
echo $name.$state.$salary;
print “$name $state $salary <br/>”;
echo “$name $state $salary <br/>”;
String Concatenator
Variables
afm -INFO2301S1Y1314
String or string variables can be concatenated using
i. Operator (‘.’) to left or to right sight of an argument.
ii. Operator (‘.=’) which appends the argument on the
right side to the argument on the left side.
Example:
<?php
$a = ’Salam ’; $b = ‘World ’; $c=1000;
$d = $a . $b; // now $d contains “Salam World"
echo $b.$c; // display ‘World 0’
$a = "Hello ";
$a .= "World!"; // now $a contains "Hello World!"
?>
 User Defined variables = by memory reference
Variables
afm -INFO2301S1Y1314
 References in PHP are a means to access the same
variable value by different memory references.
Example:
<?php
$foo = ‘Salam'; //define $foo by assigning it with a string value ‘salam‘
$bar = 'World'; //define $foo by assigning it with a string value ‘world‘
$foo = $bar; //assigning $foo by value of $bar
$bar = ‘Salam’;
print $foo; // world
$foo = &$bar; // assigning both to each other’s memory references
$foo .= ‘ My World';
print $bar;// Salam My World
?>
Managing variables
Variables
afm -INFO2301S1Y1314
Managing variables – examples
Variables
afm -INFO2301S1Y1314
<?php
$var = ‘ ‘;
// This will evaluate to TRUE so the text will be printed.
if (isset($var)) {
echo "This var is set so I will print.";
}
// var_dump is used to dump content to the output
// the return value of isset().
$a = "test";
$b = "anothertest";
var_dump(isset($a)); // TRUE
var_dump(isset($a, $b)); // TRUE
unset ($a);
var_dump(isset($a)); // FALSE
var_dump(isset($a, $b)); // FALSE
$foo = NULL;
var_dump(isset($foo)); // FALSE
?>
Variable variables (Dynamic variables)
Variables
afm -INFO2301S1Y1314
 A variable variable takes the value of a variable and
treats that as the name of a variable
Example:
<?php
$a = ‘Salam'; // a variable name $a is assigned with a value
$$a = ‘ world’; // the value of $a i.e ‘salam’ is turned to be a variable
// name and it’s assigned with a string ‘world’
echo "$a ${$a}"; // output is ‘Salam world’
echo "$a $salam"; // produce exactly the same ‘Salam world’
?>
Form variables
Variables
afm -INFO2301S1Y1314
 For each HTML form parameter, PHP creates a global variable by
the same name and makes it available to your script.
Creating the same variable names in PHP file from the form variables
requires use of extract(parameter) function in PHP file.
 Example HTML form syntaxes:
<input type=“text” name=“your_name”>
<input type=“text” name=“your_phone”>
 PHP will create a variable called $your_name for a text field named
“your_name”
PHP will create a variable called $your_phone for a text field named
“your_phone”
Form variables - example
Variables
afm -INFO2301S1Y1314
updateWarna.html
theUpdate.php
Constant
afm -INFO2301S1Y1314
 A constant is a value that, once set, cannot be
changed or unset during the execution of your
script.
 It is global in scope.
 Can be created using define() function 
defines a named constant.
 Description : bool define ( string $name , mixed $value
[$case_insensitive = false ] )
Constant
afm -INFO2301S1Y1314
 Example :
<?php
define("CONSTANT", “Salam world.");
echo CONSTANT; // outputs “Salam world."
echo Constant; // outputs "Constant" and issues a notice.
define("GREETING", “Salam you all.", true);
echo GREETING; // outputs “Salam you all."
echo Greeting; // outputs “Salam you all.”
?>
Constant
afm -INFO2301S1Y1314
 Constant () function  Return the value of the
constant indicated by name.
 constant() is useful if you need to retrieve the
value of a constant, but do not know its name. i.e.
it is stored in a variable or returned by a function.
<?php
define("MAXSIZE", 100);
echo MAXSIZE; // or
echo constant("MAXSIZE"); // same thing as the previous line
?>
Constant
afm -INFO2301S1Y1314
Built-in Constants
Constant
afm -INFO2301S1Y1314
Magic Constants
PHP
afm -INFO2301S1Y1314
THE BUILDING BLOCKS

More Related Content

What's hot

Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
Vineet Kumar Saini
 
Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
Nisa Soomro
 
Php intro by sami kz
Php intro by sami kzPhp intro by sami kz
Php intro by sami kz
sami2244
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
Bhaktaraz Bhatta
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
Muthuselvam RS
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
Henry Osborne
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHP
Ahmed Swilam
 
php basics
php basicsphp basics
php basics
Anmol Paul
 
Web 4 | Core JavaScript
Web 4 | Core JavaScriptWeb 4 | Core JavaScript
Web 4 | Core JavaScript
Mohammad Imam Hossain
 
Learn PHP Basics
Learn PHP Basics Learn PHP Basics
Learn PHP Basics
McSoftsis
 
P H P Part I, By Kian
P H P  Part  I,  By  KianP H P  Part  I,  By  Kian
P H P Part I, By Kianphelios
 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop Notes
Pamela Fox
 
Php variables (english)
Php variables (english)Php variables (english)
Php variables (english)
Mahmoud Masih Tehrani
 
Web 9 | OOP in PHP
Web 9 | OOP in PHPWeb 9 | OOP in PHP
Web 9 | OOP in PHP
Mohammad Imam Hossain
 
Php mysql
Php mysqlPhp mysql
Php mysql
Alebachew Zewdu
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
Denis Ristic
 
Programming with php
Programming with phpProgramming with php
Programming with phpsalissal
 
PHP Basic
PHP BasicPHP Basic
PHP Basic
Yoeung Vibol
 

What's hot (20)

Variables in PHP
Variables in PHPVariables in PHP
Variables in PHP
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
 
Php intro by sami kz
Php intro by sami kzPhp intro by sami kz
Php intro by sami kz
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHP
 
Operators in PHP
Operators in PHPOperators in PHP
Operators in PHP
 
php basics
php basicsphp basics
php basics
 
Web 4 | Core JavaScript
Web 4 | Core JavaScriptWeb 4 | Core JavaScript
Web 4 | Core JavaScript
 
Learn PHP Basics
Learn PHP Basics Learn PHP Basics
Learn PHP Basics
 
P H P Part I, By Kian
P H P  Part  I,  By  KianP H P  Part  I,  By  Kian
P H P Part I, By Kian
 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop Notes
 
Php variables (english)
Php variables (english)Php variables (english)
Php variables (english)
 
Web 9 | OOP in PHP
Web 9 | OOP in PHPWeb 9 | OOP in PHP
Web 9 | OOP in PHP
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
 
Programming with php
Programming with phpProgramming with php
Programming with php
 
PHP Basic
PHP BasicPHP Basic
PHP Basic
 

Viewers also liked

Php by shivitomer
Php by shivitomerPhp by shivitomer
Php by shivitomer
Shivi Tomer
 
Php(report)
Php(report)Php(report)
Php(report)Yhannah
 
6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report
6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report 6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report
6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report
c-tac
 

Viewers also liked (6)

Php by shivitomer
Php by shivitomerPhp by shivitomer
Php by shivitomer
 
Php(report)
Php(report)Php(report)
Php(report)
 
6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report
6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report 6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report
6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report
 
Php Ppt
Php PptPhp Ppt
Php Ppt
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 

Similar to 03phpbldgblock

Introduction To Php For Wit2009
Introduction To Php For Wit2009Introduction To Php For Wit2009
Introduction To Php For Wit2009
cwarren
 
FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQL
Arti Parab Academics
 
unit 1.pptx
unit 1.pptxunit 1.pptx
unit 1.pptx
adityathote3
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Muhamad Al Imran
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Muhamad Al Imran
 
Programming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th SemesterProgramming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th Semester
SanthiNivas
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
HambardeAtharva
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
Muthuganesh S
 
php AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdfphp AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdf
SVN Polytechnic Kalan Sultanpur UP
 
Training on php by cyber security infotech (csi)
Training on  php by cyber security infotech (csi)Training on  php by cyber security infotech (csi)
Training on php by cyber security infotech (csi)
Cyber Security Infotech Pvt. Ltd.
 
basics of php
 basics of php basics of php
basics of php
PRINCE KUMAR
 
Php
PhpPhp
PHP Training Part1
PHP Training Part1PHP Training Part1
PHP Training Part1
than sare
 
Php using variables-operators
Php using variables-operatorsPhp using variables-operators
Php using variables-operators
Khem Puthea
 
PHP MATERIAL
PHP MATERIALPHP MATERIAL
PHP MATERIAL
zatax
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
wahidullah mudaser
 

Similar to 03phpbldgblock (20)

Introduction To Php For Wit2009
Introduction To Php For Wit2009Introduction To Php For Wit2009
Introduction To Php For Wit2009
 
FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQL
 
Php essentials
Php essentialsPhp essentials
Php essentials
 
unit 1.pptx
unit 1.pptxunit 1.pptx
unit 1.pptx
 
Php Learning show
Php Learning showPhp Learning show
Php Learning show
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
 
Programming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th SemesterProgramming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th Semester
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
php AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdfphp AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdf
 
Training on php by cyber security infotech (csi)
Training on  php by cyber security infotech (csi)Training on  php by cyber security infotech (csi)
Training on php by cyber security infotech (csi)
 
basics of php
 basics of php basics of php
basics of php
 
Php
PhpPhp
Php
 
PHP Training Part1
PHP Training Part1PHP Training Part1
PHP Training Part1
 
Php using variables-operators
Php using variables-operatorsPhp using variables-operators
Php using variables-operators
 
PHP MATERIAL
PHP MATERIALPHP MATERIAL
PHP MATERIAL
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
Php1
Php1Php1
Php1
 

More from IIUM

How to use_000webhost
How to use_000webhostHow to use_000webhost
How to use_000webhost
IIUM
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
IIUM
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
IIUM
 
Kreydle internship-multimedia
Kreydle internship-multimediaKreydle internship-multimedia
Kreydle internship-multimedia
IIUM
 
Chap2 practice key
Chap2 practice keyChap2 practice key
Chap2 practice key
IIUM
 
Group p1
Group p1Group p1
Group p1
IIUM
 
Tutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seoTutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seo
IIUM
 
Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009
IIUM
 
03 the htm_lforms
03 the htm_lforms03 the htm_lforms
03 the htm_lforms
IIUM
 
Exercise on algo analysis answer
Exercise on algo analysis   answerExercise on algo analysis   answer
Exercise on algo analysis answer
IIUM
 
Redo midterm
Redo midtermRedo midterm
Redo midterm
IIUM
 
Heaps
HeapsHeaps
Heaps
IIUM
 
Report format
Report formatReport format
Report format
IIUM
 
Edpuzzle guidelines
Edpuzzle guidelinesEdpuzzle guidelines
Edpuzzle guidelines
IIUM
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam Paper
IIUM
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam Paper
IIUM
 
Group assignment 1 s21516
Group assignment 1 s21516Group assignment 1 s21516
Group assignment 1 s21516
IIUM
 
Avl tree-rotations
Avl tree-rotationsAvl tree-rotations
Avl tree-rotations
IIUM
 
Week12 graph
Week12   graph Week12   graph
Week12 graph
IIUM
 
Vpn
VpnVpn
Vpn
IIUM
 

More from IIUM (20)

How to use_000webhost
How to use_000webhostHow to use_000webhost
How to use_000webhost
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Kreydle internship-multimedia
Kreydle internship-multimediaKreydle internship-multimedia
Kreydle internship-multimedia
 
Chap2 practice key
Chap2 practice keyChap2 practice key
Chap2 practice key
 
Group p1
Group p1Group p1
Group p1
 
Tutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seoTutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seo
 
Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009
 
03 the htm_lforms
03 the htm_lforms03 the htm_lforms
03 the htm_lforms
 
Exercise on algo analysis answer
Exercise on algo analysis   answerExercise on algo analysis   answer
Exercise on algo analysis answer
 
Redo midterm
Redo midtermRedo midterm
Redo midterm
 
Heaps
HeapsHeaps
Heaps
 
Report format
Report formatReport format
Report format
 
Edpuzzle guidelines
Edpuzzle guidelinesEdpuzzle guidelines
Edpuzzle guidelines
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam Paper
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam Paper
 
Group assignment 1 s21516
Group assignment 1 s21516Group assignment 1 s21516
Group assignment 1 s21516
 
Avl tree-rotations
Avl tree-rotationsAvl tree-rotations
Avl tree-rotations
 
Week12 graph
Week12   graph Week12   graph
Week12 graph
 
Vpn
VpnVpn
Vpn
 

Recently uploaded

Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 

Recently uploaded (20)

Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 

03phpbldgblock

  • 2. Contents  Anatomy  Literals  DataTypes  Variables  Constant afm -INFO2301S1Y1314
  • 3.  A PHP script is a web file with .php extension and is consisting of text, HTML, and PHP instructions interspersed/intertwined throughout the file.  The PHP instructions are contained within two php tags; <?php …the opening tag & the closing tag.. ?>.  The content between these two tags is interpreted by the Zend engine (PHP module/the interpreter) and converted to regular text & HTML before being sent back to the requesting browser.  This way browser wont see any of the PHP content of PHP scripting in the file it requested.  Consider the following exercise, and have a look at source code on the browser . Anatomy afm -INFO2301S1Y1314  <html> <body> <?php $string = ‘world’; echo “<b1> Salam to the $string.<br />“ ; ?> </body
  • 4. Four different styles of tagging PHP: 1) XML style  <?php echo “salam world”; ?>  a default style (no configuration needed)  most preferred style  blend with other XML document 2) Short style  <? echo “salam world”; ?>  disabled by default  configuration needed in php.ini (short_open_tag= ‘on’)  the simplest tag style  follows SGML processing instructions style  interfere with XML document Literals afm -INFO2301S1Y1314
  • 5. Four different styles of tagging PHP: 3) script style  < script language = “php”> echo “salam world !”; </script>  Enabled by default (no configuration needed)  the longest tag style  Follows executing Javascript and VBscript style  An alternative style if using other styles cause a problem in HTML editor 4) ASP style  <% echo “salam world !”; %>  Configuration needed in php.ini (asp_tag = ‘on’)  Disabled by default  The ASP web developer friendly styles  Follows ASP processing instruction style  Interfere with XML document Literals afm -INFO2301S1Y1314
  • 6. Tagging comments in PHP: i. Blocked comments : example – /* a long paragraphed comment can be addressed and exploited within this compound. PHP scripts rendered non-executable within these symbols */ ii. Line comments: // a one line comment is addressed like this. // add another double slashes to add a next line comment Literals afm -INFO2301S1Y1314
  • 7. PHP supports four core data types: 1) Integers  whole numbers and do not contain a decimal point; integers can be expressed in decimal (base 10), octal (base 8), and hexadecimal (base 16), and are either positive or negative values. e.g. 12345 integer, 0x456fff integer in base 16(hexadecimal), 0777 integer in base 8(octal) 2) Float (also called double or reals)  fractional numbers such as 123.56 or –2.5. They must contain a decimal point or an exponent specifier, such as 1.3e–2. The letter “e” can be either uppercase or lower case. e.g. 23.45 float, .234E–2 float in scientific notation, .234e+3 float in scientific notation. Data types afm -INFO2301S1Y1314
  • 8. PHP supports four core data types: 3) String  a sequence of characters, either as a literal constant or as some kind of variable. Some notes on string operations ! : a) Single quotes treat all character equally e.g. $str = ‘$sign’ b) Double quotes DO NOT treat all characters equally. e.g. $str =“another $str”; c) String can contain escape sequences (a single character preceded with backlash ‘’). Backlash can be used for quoting ‘conflicting’ character. e.g. $str = ‘I can’t help you !’; Data types afm -INFO2301S1Y1314
  • 9. PHP supports four core data types: 3) String  escape sequences (a single character preceded with backlash ‘’).  Other uses of escape sequences as follows Data types afm -INFO2301S1Y1314
  • 10. PHP supports four core data types: 4) Boolean  or boolean logic, is a subset of algebra used for creating true/false statements. Boolean expressions use the operators AND, OR, XOR, and NOT to compare values and return a true or false result. These boolean operators are described in the following four examples:  x AND y - returns True if both x and y are true; returns False if either x or y are false.  x OR y - returns True if either x or y, or both x and y are true; returns False only if x and y are both false.  X OR y - returns True if only x or y is true; returns False if x and y are both true or both false.  NOT x - returns True if x is false (or null); returns False if x is true. Data types afm -INFO2301S1Y1314
  • 11. PHP also supports 4 other SPECIAL data types: 1) NULL 2) ARRAY 3) OBJECT 4) RESOURCES Data types afm -INFO2301S1Y1314
  • 12. Types of Variables in PHP  Predefined variables  User defined variables  Form variables related to names in an HTML form Variables afm -INFO2301S1Y1314
  • 14.  User Defined Variables = by value Variables afm -INFO2301S1Y1314 Criteria : a) A variable must have a name  Variable name starts with a dollar sign ($), followed by a character or a set of alphanumeric chars including underscore. e.g. $user, $3int, $_fraction etc. b) A variable must have value  A variable is complete as soon as a value is assigned to it. e.g. $user = ‘ali’; or $3int = 321; or $_fraction = 2.17; or $_bool= FALSE etc. A variable is complete as soon as a value is assigned to it. e.g. c) A variable must have type  A variable type goes by the data type it is initiated with. e.g. $user = ‘ali’; //a string var or $3int = 321 //int variable; or $_fraction = 2.17; // float var or $_bool= FALSE etc. d) A variable name is case sensitive  e.g. $var and $VAR are referring to two different variables.
  • 15. Displaying variable Variables afm -INFO2301S1Y1314  echo “parameter” - output one or more string and all parameters. (void echo ( string $arg1 [, string $... ] ). It can take a comma-separated list of string arguments  print “arg” - Outputs a string. (int print (string $arg). Example: $name = “Omar”; $state = “Selangor”;$salary = 10000; echo $name, $state, $salary; print $name; print $name.$state.$salary; echo $name.$state.$salary; print “$name $state $salary <br/>”; echo “$name $state $salary <br/>”;
  • 16. String Concatenator Variables afm -INFO2301S1Y1314 String or string variables can be concatenated using i. Operator (‘.’) to left or to right sight of an argument. ii. Operator (‘.=’) which appends the argument on the right side to the argument on the left side. Example: <?php $a = ’Salam ’; $b = ‘World ’; $c=1000; $d = $a . $b; // now $d contains “Salam World" echo $b.$c; // display ‘World 0’ $a = "Hello "; $a .= "World!"; // now $a contains "Hello World!" ?>
  • 17.  User Defined variables = by memory reference Variables afm -INFO2301S1Y1314  References in PHP are a means to access the same variable value by different memory references. Example: <?php $foo = ‘Salam'; //define $foo by assigning it with a string value ‘salam‘ $bar = 'World'; //define $foo by assigning it with a string value ‘world‘ $foo = $bar; //assigning $foo by value of $bar $bar = ‘Salam’; print $foo; // world $foo = &$bar; // assigning both to each other’s memory references $foo .= ‘ My World'; print $bar;// Salam My World ?>
  • 19. Managing variables – examples Variables afm -INFO2301S1Y1314 <?php $var = ‘ ‘; // This will evaluate to TRUE so the text will be printed. if (isset($var)) { echo "This var is set so I will print."; } // var_dump is used to dump content to the output // the return value of isset(). $a = "test"; $b = "anothertest"; var_dump(isset($a)); // TRUE var_dump(isset($a, $b)); // TRUE unset ($a); var_dump(isset($a)); // FALSE var_dump(isset($a, $b)); // FALSE $foo = NULL; var_dump(isset($foo)); // FALSE ?>
  • 20. Variable variables (Dynamic variables) Variables afm -INFO2301S1Y1314  A variable variable takes the value of a variable and treats that as the name of a variable Example: <?php $a = ‘Salam'; // a variable name $a is assigned with a value $$a = ‘ world’; // the value of $a i.e ‘salam’ is turned to be a variable // name and it’s assigned with a string ‘world’ echo "$a ${$a}"; // output is ‘Salam world’ echo "$a $salam"; // produce exactly the same ‘Salam world’ ?>
  • 21. Form variables Variables afm -INFO2301S1Y1314  For each HTML form parameter, PHP creates a global variable by the same name and makes it available to your script. Creating the same variable names in PHP file from the form variables requires use of extract(parameter) function in PHP file.  Example HTML form syntaxes: <input type=“text” name=“your_name”> <input type=“text” name=“your_phone”>  PHP will create a variable called $your_name for a text field named “your_name” PHP will create a variable called $your_phone for a text field named “your_phone”
  • 22. Form variables - example Variables afm -INFO2301S1Y1314 updateWarna.html theUpdate.php
  • 23. Constant afm -INFO2301S1Y1314  A constant is a value that, once set, cannot be changed or unset during the execution of your script.  It is global in scope.  Can be created using define() function  defines a named constant.  Description : bool define ( string $name , mixed $value [$case_insensitive = false ] )
  • 24. Constant afm -INFO2301S1Y1314  Example : <?php define("CONSTANT", “Salam world."); echo CONSTANT; // outputs “Salam world." echo Constant; // outputs "Constant" and issues a notice. define("GREETING", “Salam you all.", true); echo GREETING; // outputs “Salam you all." echo Greeting; // outputs “Salam you all.” ?>
  • 25. Constant afm -INFO2301S1Y1314  Constant () function  Return the value of the constant indicated by name.  constant() is useful if you need to retrieve the value of a constant, but do not know its name. i.e. it is stored in a variable or returned by a function. <?php define("MAXSIZE", 100); echo MAXSIZE; // or echo constant("MAXSIZE"); // same thing as the previous line ?>