SlideShare a Scribd company logo
1 of 19
INTRODUCTION TO
PHP
■ Origins and uses of PHP
■ Overview of PHP
■ General Syntactic Characteristics
■ Primitives
■ Operations and Expressions
■ Output
■ Control Statements
Origins and uses of PHP
• PHP was developed by Rasmus Lerdorf a member
of the Apache Group.
• In 1995 Lerdorf originally named it Personal Home
Page (PHP) but currently is known asHypertext
Preprocessor.
• PHP is a server-side, scripting language executed on
the server.
• PHP is a widely used, open-source scripting language .
Overview of PHP
PHP processor has two modes of operations:
1. Copy mode :
On the server side when the PHP processor finds XHTML code in the input
file, it simply copies it to the output file.
2. Interpret mode:
On the server side when it encounters a PHP script in the input file, it
interprets it and sendsany output of the script to the output file.
General Syntactic Characteristics
• PHP scripts can be embedded within the XHTML document by enclosing
it between the <?php and ?> tags.
• Example:
<!DOCTYPE html>
<html>
<body>
<? php
// single-line comment
# single-line comment
/*
multiple-lines
comment block
*/
echo “Hello World”;
?>
</body>
</html>
PHP allows comments to be specified in three different ways:
• Single-line comments can be specified either with # or with //.
• Multiple-line comments are delimited with /* and */ , as in many other
programming languages.
• PHP statements are terminated with semicolons(;).
• All variables in PHP begin with dollar sign($) followed by the name of the
variable. The variable names are case sensitive, $age and $Age are not same.
• Variables are not declared in PHP; they have a value and the type of the value.
• A variable name cannot start with a number. A variable name can only contain
alpha-numeric characters and underscores (A-z, 0-9, and _ ).
• A variable name must start with a letter or the underscore character.
• Reserved words of PHP
• Although variable names in PHP are case sensitive, neither reserved words nor
function names are
• For example,
there is no difference between while, WHILE, While, wHile.
Primitives, operations and expressions
• PHP has four scalar data types:
-Boolean
- Integer
-Double and
-String
• PHP has two compound data types:
- Array
- Object
• PHP has two special types:
-Resource
-NULL
• Integer type:
-PHP integer is corresponds to long in C, it is usually 32 bits.
• Double type:
-PHP's double type corresponds to C's double type.
-It can have a decimal point, exponent or both.
-There does not need to be any digits before or after the decimal point, both
are legal. EX: .345 345.
• String type:
-String literals are defined with either single (’) or double quotes (")
delimiters.
• In single quoted string literals, escape characters such as n, are not
recognized as anythingspecial and the values of embedded variables are
not substituted.
• In double-quoted string literals, escape sequences are recognized and
embedded variables arereplaced by their current values.
• Ex:
• Boolean type
Boolean values are either TRUE or FALSE, both of which are case
insensitive.
Output
• echo and print are both used to output data to the screen.
• echo has no return value and can take multiple parameters. print has return value
1 and cannot take multiple parmeters.
Ex:
Control Statements
• The control structures in PHP are very similar to C/C++/Java.
• The control statements include:
- if and if-else
-switch
- while and do-while
- for and foreach
If-elseif-else
• This statement executes different codes for more
than two conditions.
• EX: <?php
if ($x > $y)
{ echo "x is bigger than y"; }
elseif ($x == $y)
{ echo "x is equal to y"; }
else
{ echo "x is smaller than y"; }
?>
switch statement
• The switch statement is used to perform different action based on different
conditions.
• Example:
<?php
$x = 2;
switch ($x) {
case 1:printf("Choice is 1");
break;
case 2:printf("Choice is 2");
break;
case 3:printf("Choice is 3");
break;
default:printf("Choice other than 1, 2 and 3");
}
?>
While loop
• The while loop excute the
statement until the specified
condition is true.
• Ex:
<html>
<body>
<?php
$x = 1;
while($x <= 5) {
echo " $x ";
$x++;
}
?>
</body>
</html>
Do while loop
• It excutes the block of the code
and then check for the condition.
• Ex:
<html>
<body>
<?php
$x = 1;
do {
echo " $x ";
$x++;
} while ($x <= 5);
?>
</body>
</html>
For loop
• For loop is a control structure that repeats a block of code as long as a condition
is met. It's usually used to repeat a block of code a certain number of times.
• Example:
<!DOCTYPE html>
<html>
<body>
<?php
for ($x = 0; $x <= 10; $x++) {
echo "The number is: $x <br>";
}
?>
</body>
</html>
for-each
• The foreach loop works only on array and is used to loop through each
key/value pair in array.
• Example:
Thank you

More Related Content

Similar to Introduction to php contains basic....pptx

web Based Application Devlopment using PHP
web Based Application Devlopment using PHPweb Based Application Devlopment using PHP
web Based Application Devlopment using PHPmaccodder
 
Server Scripting Language -PHP
Server Scripting Language -PHPServer Scripting Language -PHP
Server Scripting Language -PHPDeo Shao
 
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)Muhamad Al Imran
 
Php tutorial from_beginner_to_master
Php tutorial from_beginner_to_masterPhp tutorial from_beginner_to_master
Php tutorial from_beginner_to_masterPrinceGuru MS
 
Basics of PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Basics of PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeBasics of PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Basics of PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeDhivyaa C.R
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive OverviewMohamed Loey
 
1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_masterjeeva indra
 
Php web development
Php web developmentPhp web development
Php web developmentRamesh Gupta
 

Similar to Introduction to php contains basic....pptx (20)

Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
 
web Based Application Devlopment using PHP
web Based Application Devlopment using PHPweb Based Application Devlopment using PHP
web Based Application Devlopment using PHP
 
Server Scripting Language -PHP
Server Scripting Language -PHPServer Scripting Language -PHP
Server Scripting Language -PHP
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
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)
 
Php unit i
Php unit iPhp unit i
Php unit i
 
Php tutorial from_beginner_to_master
Php tutorial from_beginner_to_masterPhp tutorial from_beginner_to_master
Php tutorial from_beginner_to_master
 
Basics of PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Basics of PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeBasics of PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Basics of PHP by Dr.C.R.Dhivyaa Kongu Engineering College
 
UNIT 1 (7).pptx
UNIT 1 (7).pptxUNIT 1 (7).pptx
UNIT 1 (7).pptx
 
UNIT 1 (7).pptx
UNIT 1 (7).pptxUNIT 1 (7).pptx
UNIT 1 (7).pptx
 
PPT 19.pptx
PPT 19.pptxPPT 19.pptx
PPT 19.pptx
 
Php1
Php1Php1
Php1
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive Overview
 
1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master
 
Php introduction
Php introductionPhp introduction
Php introduction
 
Php modul-1
Php modul-1Php modul-1
Php modul-1
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Php web development
Php web developmentPhp web development
Php web development
 
INTRODUCTION to php.pptx
INTRODUCTION to php.pptxINTRODUCTION to php.pptx
INTRODUCTION to php.pptx
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 

Recently uploaded

fitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptfitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptAfnanAhmad53
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxpritamlangde
 
Electromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxElectromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxNANDHAKUMARA10
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfsumitt6_25730773
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...jabtakhaidam7
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdfAldoGarca30
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...drmkjayanthikannan
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesChandrakantDivate1
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdfKamal Acharya
 
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...gragchanchal546
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdfKamal Acharya
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsvanyagupta248
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 

Recently uploaded (20)

fitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptfitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .ppt
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Electromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxElectromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptx
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To Curves
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 

Introduction to php contains basic....pptx

  • 2. ■ Origins and uses of PHP ■ Overview of PHP ■ General Syntactic Characteristics ■ Primitives ■ Operations and Expressions ■ Output ■ Control Statements
  • 3. Origins and uses of PHP • PHP was developed by Rasmus Lerdorf a member of the Apache Group. • In 1995 Lerdorf originally named it Personal Home Page (PHP) but currently is known asHypertext Preprocessor. • PHP is a server-side, scripting language executed on the server. • PHP is a widely used, open-source scripting language .
  • 4. Overview of PHP PHP processor has two modes of operations: 1. Copy mode : On the server side when the PHP processor finds XHTML code in the input file, it simply copies it to the output file. 2. Interpret mode: On the server side when it encounters a PHP script in the input file, it interprets it and sendsany output of the script to the output file.
  • 5. General Syntactic Characteristics • PHP scripts can be embedded within the XHTML document by enclosing it between the <?php and ?> tags. • Example: <!DOCTYPE html> <html> <body> <? php // single-line comment # single-line comment /* multiple-lines comment block */ echo “Hello World”; ?> </body> </html>
  • 6. PHP allows comments to be specified in three different ways: • Single-line comments can be specified either with # or with //. • Multiple-line comments are delimited with /* and */ , as in many other programming languages. • PHP statements are terminated with semicolons(;). • All variables in PHP begin with dollar sign($) followed by the name of the variable. The variable names are case sensitive, $age and $Age are not same. • Variables are not declared in PHP; they have a value and the type of the value.
  • 7. • A variable name cannot start with a number. A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ). • A variable name must start with a letter or the underscore character.
  • 8. • Reserved words of PHP • Although variable names in PHP are case sensitive, neither reserved words nor function names are • For example, there is no difference between while, WHILE, While, wHile.
  • 9. Primitives, operations and expressions • PHP has four scalar data types: -Boolean - Integer -Double and -String • PHP has two compound data types: - Array - Object • PHP has two special types: -Resource -NULL
  • 10. • Integer type: -PHP integer is corresponds to long in C, it is usually 32 bits. • Double type: -PHP's double type corresponds to C's double type. -It can have a decimal point, exponent or both. -There does not need to be any digits before or after the decimal point, both are legal. EX: .345 345. • String type: -String literals are defined with either single (’) or double quotes (") delimiters.
  • 11. • In single quoted string literals, escape characters such as n, are not recognized as anythingspecial and the values of embedded variables are not substituted. • In double-quoted string literals, escape sequences are recognized and embedded variables arereplaced by their current values. • Ex: • Boolean type Boolean values are either TRUE or FALSE, both of which are case insensitive.
  • 12. Output • echo and print are both used to output data to the screen. • echo has no return value and can take multiple parameters. print has return value 1 and cannot take multiple parmeters. Ex:
  • 13. Control Statements • The control structures in PHP are very similar to C/C++/Java. • The control statements include: - if and if-else -switch - while and do-while - for and foreach
  • 14. If-elseif-else • This statement executes different codes for more than two conditions. • EX: <?php if ($x > $y) { echo "x is bigger than y"; } elseif ($x == $y) { echo "x is equal to y"; } else { echo "x is smaller than y"; } ?>
  • 15. switch statement • The switch statement is used to perform different action based on different conditions. • Example: <?php $x = 2; switch ($x) { case 1:printf("Choice is 1"); break; case 2:printf("Choice is 2"); break; case 3:printf("Choice is 3"); break; default:printf("Choice other than 1, 2 and 3"); } ?>
  • 16. While loop • The while loop excute the statement until the specified condition is true. • Ex: <html> <body> <?php $x = 1; while($x <= 5) { echo " $x "; $x++; } ?> </body> </html> Do while loop • It excutes the block of the code and then check for the condition. • Ex: <html> <body> <?php $x = 1; do { echo " $x "; $x++; } while ($x <= 5); ?> </body> </html>
  • 17. For loop • For loop is a control structure that repeats a block of code as long as a condition is met. It's usually used to repeat a block of code a certain number of times. • Example: <!DOCTYPE html> <html> <body> <?php for ($x = 0; $x <= 10; $x++) { echo "The number is: $x <br>"; } ?> </body> </html>
  • 18. for-each • The foreach loop works only on array and is used to loop through each key/value pair in array. • Example: