SlideShare a Scribd company logo
1 of 28
Download to read offline
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 (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 shivitomerShivi 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

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)
 
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
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive Overview
 

More from IIUM

How to use_000webhost
How to use_000webhostHow to use_000webhost
How to use_000webhostIIUM
 
Chapter 2
Chapter 2Chapter 2
Chapter 2IIUM
 
Chapter 1
Chapter 1Chapter 1
Chapter 1IIUM
 
Kreydle internship-multimedia
Kreydle internship-multimediaKreydle internship-multimedia
Kreydle internship-multimediaIIUM
 
Chap2 practice key
Chap2 practice keyChap2 practice key
Chap2 practice keyIIUM
 
Group p1
Group p1Group p1
Group p1IIUM
 
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 seoIIUM
 
Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009IIUM
 
03 the htm_lforms
03 the htm_lforms03 the htm_lforms
03 the htm_lformsIIUM
 
Exercise on algo analysis answer
Exercise on algo analysis   answerExercise on algo analysis   answer
Exercise on algo analysis answerIIUM
 
Redo midterm
Redo midtermRedo midterm
Redo midtermIIUM
 
Heaps
HeapsHeaps
HeapsIIUM
 
Report format
Report formatReport format
Report formatIIUM
 
Edpuzzle guidelines
Edpuzzle guidelinesEdpuzzle guidelines
Edpuzzle guidelinesIIUM
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam PaperIIUM
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam PaperIIUM
 
Group assignment 1 s21516
Group assignment 1 s21516Group assignment 1 s21516
Group assignment 1 s21516IIUM
 
Avl tree-rotations
Avl tree-rotationsAvl tree-rotations
Avl tree-rotationsIIUM
 
Week12 graph
Week12   graph Week12   graph
Week12 graph IIUM
 
Vpn
VpnVpn
VpnIIUM
 

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

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 

Recently uploaded (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 

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