SlideShare a Scribd company logo
1 of 23
PHP: THE BASICS
By : Mr. Shehrevar Davierwala
Only for educational Purpose
WHAT IS IT?
• PHP is a scripting language commonly used on web
servers.
• Stands for “PHP: Hypertext Preprocessor”
• Open source
• Embedded code
• Comparable with ASP
• Multiple operating systems/web servers
Only for educational Purpose
THE PHP RESOURCE
www.php.net
Only for educational Purpose
WHAT CAN IT DO?
• Dynamic generation of web-page content
• Database interaction
• Processing of user supplied data
• Email
• File handling
• Text processing
• Network interaction
• And more…
Only for educational Purpose
FUNDAMENTALS
• PHP is embedded within xhtml pages within the
tags: <?php … ?>
• The short version of these tags can also be used: <?
… ?>
• Each line of PHP is terminated, like MySQL, with a
semi-colon.
Only for educational Purpose
HELLO WORLD!
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo ‘<p>Hello World!</p>’; ?>
</body>
</html>
Only for educational Purpose
PREPARING TO CODE WITH PHP
Only for educational Purpose
LITERALS..
• All strings must be enclosed in single of double
quotes: ‘Hello’ or “Hello”.
• Numbers are not in enclosed in quotes: 1 or 45 or
34.564
• Booleans (true/flase) can be written directly as true
or false.
Only for educational Purpose
COMMENTS
// This is a comment
# This is also a comment
/* This is a comment
that is spread over
multiple lines */
• Do not nest multi-line comments
• // recommended over #
Only for educational Purpose
COMMENTS
<?php
// this is a comment
echo ‘Hello World!’;
/* another
multi-line comment */
?>
Only for educational Purpose
DISPLAYING DATA
• There are two language constructs available to
display data: print() and echo().
• They can be used with or without brackets.
• Note that the data ‘displayed’ by PHP is actually
parsed by your browser as HTML. View source to see
actual output.
Only for educational Purpose
DISPLAYING DATA
<?php
echo ‘Hello World!<br />’;
echo(‘Hello World!<br />’);
print ‘Hello World!<br />’;
print(‘Hello World!<br />’);
?>
Only for educational Purpose
ESCAPING CHARACTERS
• Some characters are considered ‘special’
• Escape these with a backslash 
• Special characters will be flagged when they arise,
for example a double or single quote belong in this
group…
Only for educational Purpose
ESCAPING CHARACTERS
<?php
// Claire O’Reilly said “Hello”.
echo ‘Claire O’Reilly ’;
echo “said ”Hello”.”;
?>
Only for educational Purpose
VARIABLES: WHAT ARE THEY?
• When we work in PHP, we often need a labelled
place to store a value (be it a string, number,
whatever) so we can use it in multiple places in our
script.
• These labelled ‘places’ are called
VARIABLES
Only for educational Purpose
VARIABLES: NAMING
• $ followed by variable name
• Case sensitive
• $variable differs from $Variable
• Stick to lower-case to be sure!
• Name must started with a letter or an underscore
• Followed by any number of letters, numbers and
underscores
Only for educational Purpose
VARIABLES: EXAMPLE
<?php
$name = ‘Phil’;
$age = 23;
echo $name;
echo ’ is ‘;
echo $age;
// Phil is 23
?>
Only for educational Purpose
CONSTANTS
•Constants (unchangeable
variables) can also be defined.
•Each constant is given a name
(note no preceding dollar is
applied here).
•By convention, constant names
are usually in UPPERCASE.
Only for educational Purpose
CONSTANTS
<?php
define(‘NAME’,‘Phil’);
define(‘AGE’,23);
echo NAME;
echo ’ is ‘;
echo AGE;
// Phil is 23
?>
Only for educational Purpose
“ OR ‘ ?
• There is a difference between strings written in single
and double quotes.
• In a double-quoted string any variable names are
expanded to their values.
• In a single-quoted string, no variable expansion
takes place.
Only for educational Purpose
“ OR ‘ ?
<?php
$name = ‘Phil’;
$age = 23;
echo “$name is $age”;
// Phil is 23
?>
Only for educational Purpose
“ OR ‘ ?
<?php
$name = ‘Phil’;
$age = 23;
echo ‘$name is $age’;
// $name is $age
?>
Only for educational Purpose
REVIEW
• We’ve started PHP..
• Escaping XHTML
• Comments
• Basic Syntax
• Variables
• Constants
Only for educational Purpose

More Related Content

What's hot (20)

Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
01 basics
01 basics01 basics
01 basics
 
php basic
php basicphp basic
php basic
 
Php basics
Php basicsPhp basics
Php basics
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive Overview
 
PHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginnersPHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginners
 
Php hypertext pre-processor
Php   hypertext pre-processorPhp   hypertext pre-processor
Php hypertext pre-processor
 
Php introduction
Php introductionPhp introduction
Php introduction
 
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
 
Php tutorial
Php  tutorialPhp  tutorial
Php tutorial
 
Php unit i
Php unit iPhp unit i
Php unit i
 
PHP - Introduction to PHP
PHP -  Introduction to PHPPHP -  Introduction to PHP
PHP - Introduction to PHP
 
01 Php Introduction
01 Php Introduction01 Php Introduction
01 Php Introduction
 
Php introduction and configuration
Php introduction and configurationPhp introduction and configuration
Php introduction and configuration
 
Welcome to computer programmer 2
Welcome to computer programmer 2Welcome to computer programmer 2
Welcome to computer programmer 2
 
php app development 1
php app development 1php app development 1
php app development 1
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Tech talk php_cms
Tech talk php_cmsTech talk php_cms
Tech talk php_cms
 
Introduction to-php
Introduction to-phpIntroduction to-php
Introduction to-php
 

Viewers also liked (20)

Tech talk webtech
Tech talk webtechTech talk webtech
Tech talk webtech
 
Basic
BasicBasic
Basic
 
Binary numbersystem
Binary numbersystemBinary numbersystem
Binary numbersystem
 
numbers system
numbers systemnumbers system
numbers system
 
Java operators
Java operatorsJava operators
Java operators
 
Futbool Jose David
Futbool Jose DavidFutbool Jose David
Futbool Jose David
 
JKLKJ
JKLKJJKLKJ
JKLKJ
 
Bourcher
BourcherBourcher
Bourcher
 
CICS TS for OS 390 Problem Analysis
CICS TS for OS 390 Problem AnalysisCICS TS for OS 390 Problem Analysis
CICS TS for OS 390 Problem Analysis
 
St Paul Federal Certificate of Recognition
St Paul Federal Certificate of RecognitionSt Paul Federal Certificate of Recognition
St Paul Federal Certificate of Recognition
 
Confraternização Lagoa 2014
Confraternização Lagoa 2014Confraternização Lagoa 2014
Confraternização Lagoa 2014
 
Fact
FactFact
Fact
 
Alumnos Que Ingresaron En 2004
Alumnos Que Ingresaron En 2004Alumnos Que Ingresaron En 2004
Alumnos Que Ingresaron En 2004
 
To Whom It May Concern
To Whom It May ConcernTo Whom It May Concern
To Whom It May Concern
 
Enfermería
EnfermeríaEnfermería
Enfermería
 
杜拜除帆船飯店外還有更棒的
杜拜除帆船飯店外還有更棒的杜拜除帆船飯店外還有更棒的
杜拜除帆船飯店外還有更棒的
 
diabetes uk - police
diabetes uk - policediabetes uk - police
diabetes uk - police
 
S4 tarea4 garua
S4 tarea4 garuaS4 tarea4 garua
S4 tarea4 garua
 
ADEOYE CV 2015
ADEOYE  CV 2015ADEOYE  CV 2015
ADEOYE CV 2015
 
Insights from Conversations with Financial Consumers
Insights from Conversations with Financial ConsumersInsights from Conversations with Financial Consumers
Insights from Conversations with Financial Consumers
 

Similar to Ph pbasics

Similar to Ph pbasics (20)

01-basics.ppt
01-basics.ppt01-basics.ppt
01-basics.ppt
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Materi Dasar PHP
Materi Dasar PHPMateri Dasar PHP
Materi Dasar PHP
 
Upstate CSCI 450 PHP
Upstate CSCI 450 PHPUpstate CSCI 450 PHP
Upstate CSCI 450 PHP
 
php basic part one
php basic part onephp basic part one
php basic part one
 
INTRODUCTION to php.pptx
INTRODUCTION to php.pptxINTRODUCTION to php.pptx
INTRODUCTION to php.pptx
 
php Chapter 1.pptx
php Chapter 1.pptxphp Chapter 1.pptx
php Chapter 1.pptx
 
PHP Variables and scopes
PHP Variables and scopesPHP Variables and scopes
PHP Variables and scopes
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
 
Php tizag tutorial
Php tizag tutorialPhp tizag tutorial
Php tizag tutorial
 
php_tizag_tutorial
php_tizag_tutorialphp_tizag_tutorial
php_tizag_tutorial
 
Php tizag tutorial
Php tizag tutorial Php tizag tutorial
Php tizag tutorial
 
php_tizag_tutorial
php_tizag_tutorialphp_tizag_tutorial
php_tizag_tutorial
 
Php tizag tutorial
Php tizag tutorialPhp tizag tutorial
Php tizag tutorial
 
PHP learning
PHP learningPHP learning
PHP learning
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13
 
Php1
Php1Php1
Php1
 
PHP
PHPPHP
PHP
 
php (Hypertext Preprocessor)
php (Hypertext Preprocessor)php (Hypertext Preprocessor)
php (Hypertext Preprocessor)
 

More from Shehrevar Davierwala

Build brand reputation using facebook
Build brand reputation using facebookBuild brand reputation using facebook
Build brand reputation using facebookShehrevar Davierwala
 
Learn Digital Marketing : 0 to Hero Day 1
Learn Digital Marketing :  0 to Hero Day 1 Learn Digital Marketing :  0 to Hero Day 1
Learn Digital Marketing : 0 to Hero Day 1 Shehrevar Davierwala
 
Digital Marketing for Sustainable Business - Afghan Perspective
Digital Marketing for Sustainable Business - Afghan Perspective  Digital Marketing for Sustainable Business - Afghan Perspective
Digital Marketing for Sustainable Business - Afghan Perspective Shehrevar Davierwala
 
Developing stunning website in clicks - 2
Developing stunning website in clicks - 2Developing stunning website in clicks - 2
Developing stunning website in clicks - 2Shehrevar Davierwala
 
Developing stunning website in clicks
Developing stunning website in clicksDeveloping stunning website in clicks
Developing stunning website in clicksShehrevar Davierwala
 

More from Shehrevar Davierwala (20)

Introduction_Swift
Introduction_SwiftIntroduction_Swift
Introduction_Swift
 
PsudoCode.pptx
PsudoCode.pptxPsudoCode.pptx
PsudoCode.pptx
 
Number System.pptx
Number System.pptxNumber System.pptx
Number System.pptx
 
Java Script (Module 1).pptx
Java Script (Module 1).pptxJava Script (Module 1).pptx
Java Script (Module 1).pptx
 
Website in Clicks Day 2
Website in Clicks Day 2Website in Clicks Day 2
Website in Clicks Day 2
 
Develop Website in Clicks
Develop Website in ClicksDevelop Website in Clicks
Develop Website in Clicks
 
Build Virtual Assistant Using AI
Build Virtual Assistant Using AI Build Virtual Assistant Using AI
Build Virtual Assistant Using AI
 
Build brand reputation using facebook
Build brand reputation using facebookBuild brand reputation using facebook
Build brand reputation using facebook
 
Digital Marketing Session 2
Digital Marketing Session 2Digital Marketing Session 2
Digital Marketing Session 2
 
Learn Digital Marketing : 0 to Hero Day 1
Learn Digital Marketing :  0 to Hero Day 1 Learn Digital Marketing :  0 to Hero Day 1
Learn Digital Marketing : 0 to Hero Day 1
 
Standard template
Standard templateStandard template
Standard template
 
Digital Marketing for Sustainable Business - Afghan Perspective
Digital Marketing for Sustainable Business - Afghan Perspective  Digital Marketing for Sustainable Business - Afghan Perspective
Digital Marketing for Sustainable Business - Afghan Perspective
 
Developing stunning website in clicks - 2
Developing stunning website in clicks - 2Developing stunning website in clicks - 2
Developing stunning website in clicks - 2
 
Developing stunning website in clicks
Developing stunning website in clicksDeveloping stunning website in clicks
Developing stunning website in clicks
 
Google forms for data analysis
Google forms for data analysisGoogle forms for data analysis
Google forms for data analysis
 
Webdesign session1
Webdesign session1Webdesign session1
Webdesign session1
 
Array in Java
Array in JavaArray in Java
Array in Java
 
Comp hardware Introduction
Comp hardware IntroductionComp hardware Introduction
Comp hardware Introduction
 
Jstreams
JstreamsJstreams
Jstreams
 
Rdbms concepts
Rdbms conceptsRdbms concepts
Rdbms concepts
 

Recently uploaded

Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 

Recently uploaded (20)

Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 

Ph pbasics

  • 1. PHP: THE BASICS By : Mr. Shehrevar Davierwala Only for educational Purpose
  • 2. WHAT IS IT? • PHP is a scripting language commonly used on web servers. • Stands for “PHP: Hypertext Preprocessor” • Open source • Embedded code • Comparable with ASP • Multiple operating systems/web servers Only for educational Purpose
  • 3. THE PHP RESOURCE www.php.net Only for educational Purpose
  • 4. WHAT CAN IT DO? • Dynamic generation of web-page content • Database interaction • Processing of user supplied data • Email • File handling • Text processing • Network interaction • And more… Only for educational Purpose
  • 5. FUNDAMENTALS • PHP is embedded within xhtml pages within the tags: <?php … ?> • The short version of these tags can also be used: <? … ?> • Each line of PHP is terminated, like MySQL, with a semi-colon. Only for educational Purpose
  • 6. HELLO WORLD! <html> <head> <title>PHP Test</title> </head> <body> <?php echo ‘<p>Hello World!</p>’; ?> </body> </html> Only for educational Purpose
  • 7. PREPARING TO CODE WITH PHP Only for educational Purpose
  • 8. LITERALS.. • All strings must be enclosed in single of double quotes: ‘Hello’ or “Hello”. • Numbers are not in enclosed in quotes: 1 or 45 or 34.564 • Booleans (true/flase) can be written directly as true or false. Only for educational Purpose
  • 9. COMMENTS // This is a comment # This is also a comment /* This is a comment that is spread over multiple lines */ • Do not nest multi-line comments • // recommended over # Only for educational Purpose
  • 10. COMMENTS <?php // this is a comment echo ‘Hello World!’; /* another multi-line comment */ ?> Only for educational Purpose
  • 11. DISPLAYING DATA • There are two language constructs available to display data: print() and echo(). • They can be used with or without brackets. • Note that the data ‘displayed’ by PHP is actually parsed by your browser as HTML. View source to see actual output. Only for educational Purpose
  • 12. DISPLAYING DATA <?php echo ‘Hello World!<br />’; echo(‘Hello World!<br />’); print ‘Hello World!<br />’; print(‘Hello World!<br />’); ?> Only for educational Purpose
  • 13. ESCAPING CHARACTERS • Some characters are considered ‘special’ • Escape these with a backslash • Special characters will be flagged when they arise, for example a double or single quote belong in this group… Only for educational Purpose
  • 14. ESCAPING CHARACTERS <?php // Claire O’Reilly said “Hello”. echo ‘Claire O’Reilly ’; echo “said ”Hello”.”; ?> Only for educational Purpose
  • 15. VARIABLES: WHAT ARE THEY? • When we work in PHP, we often need a labelled place to store a value (be it a string, number, whatever) so we can use it in multiple places in our script. • These labelled ‘places’ are called VARIABLES Only for educational Purpose
  • 16. VARIABLES: NAMING • $ followed by variable name • Case sensitive • $variable differs from $Variable • Stick to lower-case to be sure! • Name must started with a letter or an underscore • Followed by any number of letters, numbers and underscores Only for educational Purpose
  • 17. VARIABLES: EXAMPLE <?php $name = ‘Phil’; $age = 23; echo $name; echo ’ is ‘; echo $age; // Phil is 23 ?> Only for educational Purpose
  • 18. CONSTANTS •Constants (unchangeable variables) can also be defined. •Each constant is given a name (note no preceding dollar is applied here). •By convention, constant names are usually in UPPERCASE. Only for educational Purpose
  • 19. CONSTANTS <?php define(‘NAME’,‘Phil’); define(‘AGE’,23); echo NAME; echo ’ is ‘; echo AGE; // Phil is 23 ?> Only for educational Purpose
  • 20. “ OR ‘ ? • There is a difference between strings written in single and double quotes. • In a double-quoted string any variable names are expanded to their values. • In a single-quoted string, no variable expansion takes place. Only for educational Purpose
  • 21. “ OR ‘ ? <?php $name = ‘Phil’; $age = 23; echo “$name is $age”; // Phil is 23 ?> Only for educational Purpose
  • 22. “ OR ‘ ? <?php $name = ‘Phil’; $age = 23; echo ‘$name is $age’; // $name is $age ?> Only for educational Purpose
  • 23. REVIEW • We’ve started PHP.. • Escaping XHTML • Comments • Basic Syntax • Variables • Constants Only for educational Purpose

Editor's Notes

  1. Using your favoured text editor (e.g. Notepad) create the file on the slide… Save it in your web space as hello.php and navigate to the file via your web browser You should see Hello World! On the page… If that has worked replace all with phpinfo(); and run again… You should now see a page with lots of information about the PHP installation – this will become useful later! NOT XHTML (NO DOCTYPE SETTING ETC) TO SAVE SPACE ON PAGE…
  2. Demo the fact that the variable can be changed.. $name = ‘Phil’; $age = 23; $name = ‘Ed’; echo $name; echo ’ is ‘; echo $age; // Ed is 23
  3. A constant is an identifier for a single value… Cannot be changed during execution (or undefined) Same naming convention as a standard variable (just no $) Are global (can be accessed anywhere – within functions, etc.) There are many predefined constants (see www.php.net for the long list!) Core constants Set in the PHP core… Mostly to do with error tracking and also core items like version, install directories, etc. Standard constants Loads more! Extension constants These are set by extensions if they are loaded See individual extension descriptions for details
  4. Demo the fact that the variable can be changed.. $name = ‘Phil’; $age = 23; $name = ‘Ed’; echo $name; echo ’ is ‘; echo $age; // Ed is 23
  5. Demo the fact that the variable can be changed.. $name = ‘Phil’; $age = 23; $name = ‘Ed’; echo $name; echo ’ is ‘; echo $age; // Ed is 23