SlideShare a Scribd company logo
1 of 23
PHP Workshop ‹
#
›
PHP: The Basics
PHP Workshop ‹
#
›
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
PHP Workshop ‹
#
›
The PHP Resource
www.php.net
PHP Workshop ‹
#
›
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…
PHP Workshop ‹
#
›
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.
PHP Workshop ‹
#
›
Hello World!
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo ‘<p>Hello World!</p>’; ?>
</body>
</html>
PHP Workshop ‹
#
›
Preparing to code with PHP
PHP Workshop ‹
#
›
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.
PHP Workshop ‹
#
›
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 #
PHP Workshop ‹
#
›
Comments
<?php
// this is a comment
echo ‘Hello World!’;
/* another
multi-line comment */
?>
PHP Workshop ‹
#
›
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.
PHP Workshop ‹
#
›
Displaying data
<?php
echo ‘Hello World!<br />’;
echo(‘Hello World!<br />’);
print ‘Hello World!<br />’;
print(‘Hello World!<br />’);
?>
PHP Workshop ‹
#
›
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…
PHP Workshop ‹
#
›
Escaping Characters
<?php
// Claire O’Reilly said “Hello”.
echo ‘Claire O’Reilly ’;
echo “said ”Hello”.”;
?>
PHP Workshop ‹
#
›
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
PHP Workshop ‹
#
›
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
PHP Workshop ‹
#
›
Variables: example
<?php
$name = ‘Phil’;
$age = 23;
echo $name;
echo ’ is ‘;
echo $age;
// Phil is 23
?>
PHP Workshop ‹
#
›
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.
PHP Workshop ‹
#
›
Constants
<?php
define(‘NAME’,‘Phil’);
define(‘AGE’,23);
echo NAME;
echo ’ is ‘;
echo AGE;
// Phil is 23
?>
PHP Workshop ‹
#
›
“ 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.
PHP Workshop ‹
#
›
“ or ‘ ?
<?php
$name = ‘Phil’;
$age = 23;
echo “$name is $age”;
// Phil is 23
?>
PHP Workshop ‹
#
›
“ or ‘ ?
<?php
$name = ‘Phil’;
$age = 23;
echo ‘$name is $age’;
// $name is $age
?>
PHP Workshop ‹
#
›
Review
• We’ve started PHP..
– Escaping XHTML
– Comments
– Basic Syntax
– Variables
– Constants

More Related Content

Similar to 01-basics.ppt

Similar to 01-basics.ppt (20)

Php mysql
Php mysqlPhp mysql
Php mysql
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
 
php app development 1
php app development 1php app development 1
php app development 1
 
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
 
Introduction to-php
Introduction to-phpIntroduction to-php
Introduction to-php
 
Upstate CSCI 450 PHP
Upstate CSCI 450 PHPUpstate CSCI 450 PHP
Upstate CSCI 450 PHP
 
basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)
 
Php introduction
Php introductionPhp introduction
Php introduction
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
INTRODUCTION to php.pptx
INTRODUCTION to php.pptxINTRODUCTION to php.pptx
INTRODUCTION to php.pptx
 
HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.js
 
Wt unit 4 server side technology-2
Wt unit 4 server side technology-2Wt unit 4 server side technology-2
Wt unit 4 server side technology-2
 
PHP Introduction and Training Material
PHP Introduction and Training MaterialPHP Introduction and Training Material
PHP Introduction and Training Material
 
Php
PhpPhp
Php
 
php basic part one
php basic part onephp basic part one
php basic part one
 
Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010
 
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
 
PHP
PHPPHP
PHP
 
Lecture8
Lecture8Lecture8
Lecture8
 

Recently uploaded

DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage examplePragyanshuParadkar1
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixingviprabot1
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture designssuser87fa0c1
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 

Recently uploaded (20)

Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage example
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixing
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 

01-basics.ppt

  • 2. PHP Workshop ‹ # › 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
  • 3. PHP Workshop ‹ # › The PHP Resource www.php.net
  • 4. PHP Workshop ‹ # › 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…
  • 5. PHP Workshop ‹ # › 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.
  • 6. PHP Workshop ‹ # › Hello World! <html> <head> <title>PHP Test</title> </head> <body> <?php echo ‘<p>Hello World!</p>’; ?> </body> </html>
  • 8. PHP Workshop ‹ # › 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.
  • 9. PHP Workshop ‹ # › 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 #
  • 10. PHP Workshop ‹ # › Comments <?php // this is a comment echo ‘Hello World!’; /* another multi-line comment */ ?>
  • 11. PHP Workshop ‹ # › 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.
  • 12. PHP Workshop ‹ # › Displaying data <?php echo ‘Hello World!<br />’; echo(‘Hello World!<br />’); print ‘Hello World!<br />’; print(‘Hello World!<br />’); ?>
  • 13. PHP Workshop ‹ # › 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…
  • 14. PHP Workshop ‹ # › Escaping Characters <?php // Claire O’Reilly said “Hello”. echo ‘Claire O’Reilly ’; echo “said ”Hello”.”; ?>
  • 15. PHP Workshop ‹ # › 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
  • 16. PHP Workshop ‹ # › 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
  • 17. PHP Workshop ‹ # › Variables: example <?php $name = ‘Phil’; $age = 23; echo $name; echo ’ is ‘; echo $age; // Phil is 23 ?>
  • 18. PHP Workshop ‹ # › 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.
  • 20. PHP Workshop ‹ # › “ 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.
  • 21. PHP Workshop ‹ # › “ or ‘ ? <?php $name = ‘Phil’; $age = 23; echo “$name is $age”; // Phil is 23 ?>
  • 22. PHP Workshop ‹ # › “ or ‘ ? <?php $name = ‘Phil’; $age = 23; echo ‘$name is $age’; // $name is $age ?>
  • 23. PHP Workshop ‹ # › Review • We’ve started PHP.. – Escaping XHTML – Comments – Basic Syntax – Variables – Constants

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