SlideShare une entreprise Scribd logo
1  sur  13
Corporate Training Material
Design & Created
By
Msxpert Solutions
What is PHP used for?
What is PHP?
What does PHP code look like?
Echo
Comments
Variables
Constant
What is PHP Used For?
 PHP is a general-purpose server-side scripting
language originally designed for web development to
produce dynamic web pages
 PHP can interact with MySQL databases
What is PHP?
 PHP == ‘Hypertext Preprocessor’
 Open-source, server-side scripting language
 Used to generate dynamic web-pages
 PHP scripts reside between reserved PHP tags
 This allows the programmer to embed PHP scripts within
HTML pages
 Interpreted language, scripts are parsed at run-time rather
than compiled beforehand
 Executed on the server-side
 Source-code not visible by client
 ‘View Source’ in browsers does not display the PHP code
 Various built-in functions allow for fast development
 Compatible with many popular databases
What does PHP code look like?
 Structurally similar to C/C++
 Supports procedural and object-oriented
paradigm (to some degree)
 All PHP statements end with a semi-colon
 Each PHP script must be enclosed in the reserved
PHP tag
<?php
…
?>
Echo
 The PHP command ‘echo’ is used to output the
parameters passed to it
 The typical usage for this is to send data to the
client’s web-browser
 Syntax
 void echo (string arg1 [, string argn...])
 In practice, arguments are not passed in
parentheses since echo is a language construct
rather than an actual function
Echo example
 Notice how echo ‘5x5=$xyz’ outputs $xyz rather than replacing it with 25
 Strings in single quotes (‘ ’) are not interpreted or evaluated by PHP
 This is true for both variables and character escape-sequences (such as “n” or
“”)
<?php
$xyz = 25; // Numerical variable
$bar = “Hello”; // String variable
echo $bar; // Outputs Hello
echo $xyz,$bar; // Outputs 25Hello
echo “5x5=”,$xyz; // Outputs 5x5=25
echo “5x5=$xyz”; // Outputs 5x5=25
echo ‘5x5=$xyz’; // Outputs 5x5=$xyz
?>
Comments in PHP
 Standard C, C++, and shell comment symbols
// for one line comment
# for one line comment
/* for multiple line.
These can span multiple lines */
Rules for variables:
•A variable starts with the $ sign, followed by the name of
the variable
•A variable name must start with a letter or the underscore
character($nam and $_nam)
•A variable name cannot start with a number
•A variable name can only contain alpha-numeric
characters and underscores (A-z, 0-9, and _ )
•Variable names are case-sensitive ($nam and $NAM are
two different variables)
Variables
Variables in PHP
OUTPUT is:
My Friends
2
I love My Friends
I love My Friends.
Note: 1.When you assign a text value to a
variable, put quotes around the
value.eg.”Hello Friends”
2.Here dot(.) is used for concatenation of
string)
<!DOCTYPE html>
<html>
<body>
<?php
$txt = “My Friends";
$x = 2;
echo $txt;
echo "<br>";
echo $x;
echo “I love $txt";
echo”<br>”;
echo ”I love”.$txt.”!”;
?>
</body>
</html>
Constant in PHP
A constant is name for a simple value. The value cannot be
changed during the script.
To create a constant, use the define() function.
Syntex
define(name, value, case-insensitive)
Parameters:
name: tell the name of the constant
value: tell the value of the constant
case-insensitive: tell whether the constant name is
case-insensitive. Default is false
Constant in PHP
<?php
define(“WELCOME", “to our office”,true);
echo welcome;
?>
<?php
define(“WELCOME", “to our office”);
echo WELCOME;
?>
The example below creates a constant with a case-sensitive name:
The example below creates a constant with a case-insensitive name:
NOTE:Constants are automatically global and can be used inthe entire script.
Differences between constants and variables
 There is no need to write a dollar sign ($) before a
constant, where as in Variable one has to write a dollar
sign.
 Constants cannot be defined by simple assignment,
they may only be defined using the define() function.
 Constants may be defined and accessed anywhere
without regard to variable scoping rules.
 Once the Constants have been set, may not be
redefined or undefined.

Contenu connexe

Tendances (20)

Basic PHP
Basic PHPBasic PHP
Basic PHP
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Php(report)
Php(report)Php(report)
Php(report)
 
Lesson 4 constant
Lesson 4  constantLesson 4  constant
Lesson 4 constant
 
slidesharenew1
slidesharenew1slidesharenew1
slidesharenew1
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
 
Php string function
Php string function Php string function
Php string function
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
 
PHP tutorial | ptutorial
PHP tutorial | ptutorialPHP tutorial | ptutorial
PHP tutorial | ptutorial
 
Php Operators N Controllers
Php Operators N ControllersPhp Operators N Controllers
Php Operators N Controllers
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Php Loop
Php LoopPhp Loop
Php Loop
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Advanced php
Advanced phpAdvanced php
Advanced php
 
Loops PHP 04
Loops PHP 04Loops PHP 04
Loops PHP 04
 
PHP variables
PHP  variablesPHP  variables
PHP variables
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
PHP
PHPPHP
PHP
 

Similaire à PHP Introduction and Training Material

Similaire à PHP Introduction and Training Material (20)

Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
 
Prersentation
PrersentationPrersentation
Prersentation
 
Lecture8
Lecture8Lecture8
Lecture8
 
Materi Dasar PHP
Materi Dasar PHPMateri Dasar PHP
Materi Dasar PHP
 
Php assignment help
Php assignment helpPhp assignment help
Php assignment help
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
php app development 1
php app development 1php app development 1
php app development 1
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 
Php
PhpPhp
Php
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
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)
 
Php essentials
Php essentialsPhp essentials
Php essentials
 
Php introduction
Php introductionPhp introduction
Php introduction
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Day1
Day1Day1
Day1
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1
 
Introduction to-php
Introduction to-phpIntroduction to-php
Introduction to-php
 

Dernier

VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...singhpriety023
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirtrahman018755
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...SUHANI PANDEY
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Delhi Call girls
 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubaikojalkojal131
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.soniya singh
 
Al Barsha Night Partner +0567686026 Call Girls Dubai
Al Barsha Night Partner +0567686026 Call Girls  DubaiAl Barsha Night Partner +0567686026 Call Girls  Dubai
Al Barsha Night Partner +0567686026 Call Girls DubaiEscorts Call Girls
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...Neha Pandey
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtrahman018755
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceDelhi Call girls
 
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.soniya singh
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...Escorts Call Girls
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC
 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...tanu pandey
 
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts ServiceReal Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts ServiceEscorts Call Girls
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...Diya Sharma
 
VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...
VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...
VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...SUHANI PANDEY
 

Dernier (20)

VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
 
Al Barsha Night Partner +0567686026 Call Girls Dubai
Al Barsha Night Partner +0567686026 Call Girls  DubaiAl Barsha Night Partner +0567686026 Call Girls  Dubai
Al Barsha Night Partner +0567686026 Call Girls Dubai
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
Russian Call Girls in %(+971524965298  )#  Call Girls in DubaiRussian Call Girls in %(+971524965298  )#  Call Girls in Dubai
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
 
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
 
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
 
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts ServiceReal Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
 
VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...
VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...
VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...
 

PHP Introduction and Training Material

  • 1. Corporate Training Material Design & Created By Msxpert Solutions
  • 2. What is PHP used for? What is PHP? What does PHP code look like? Echo Comments Variables Constant
  • 3. What is PHP Used For?  PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages  PHP can interact with MySQL databases
  • 4. What is PHP?  PHP == ‘Hypertext Preprocessor’  Open-source, server-side scripting language  Used to generate dynamic web-pages  PHP scripts reside between reserved PHP tags  This allows the programmer to embed PHP scripts within HTML pages  Interpreted language, scripts are parsed at run-time rather than compiled beforehand  Executed on the server-side  Source-code not visible by client  ‘View Source’ in browsers does not display the PHP code  Various built-in functions allow for fast development  Compatible with many popular databases
  • 5. What does PHP code look like?  Structurally similar to C/C++  Supports procedural and object-oriented paradigm (to some degree)  All PHP statements end with a semi-colon  Each PHP script must be enclosed in the reserved PHP tag <?php … ?>
  • 6. Echo  The PHP command ‘echo’ is used to output the parameters passed to it  The typical usage for this is to send data to the client’s web-browser  Syntax  void echo (string arg1 [, string argn...])  In practice, arguments are not passed in parentheses since echo is a language construct rather than an actual function
  • 7. Echo example  Notice how echo ‘5x5=$xyz’ outputs $xyz rather than replacing it with 25  Strings in single quotes (‘ ’) are not interpreted or evaluated by PHP  This is true for both variables and character escape-sequences (such as “n” or “”) <?php $xyz = 25; // Numerical variable $bar = “Hello”; // String variable echo $bar; // Outputs Hello echo $xyz,$bar; // Outputs 25Hello echo “5x5=”,$xyz; // Outputs 5x5=25 echo “5x5=$xyz”; // Outputs 5x5=25 echo ‘5x5=$xyz’; // Outputs 5x5=$xyz ?>
  • 8. Comments in PHP  Standard C, C++, and shell comment symbols // for one line comment # for one line comment /* for multiple line. These can span multiple lines */
  • 9. Rules for variables: •A variable starts with the $ sign, followed by the name of the variable •A variable name must start with a letter or the underscore character($nam and $_nam) •A variable name cannot start with a number •A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) •Variable names are case-sensitive ($nam and $NAM are two different variables) Variables
  • 10. Variables in PHP OUTPUT is: My Friends 2 I love My Friends I love My Friends. Note: 1.When you assign a text value to a variable, put quotes around the value.eg.”Hello Friends” 2.Here dot(.) is used for concatenation of string) <!DOCTYPE html> <html> <body> <?php $txt = “My Friends"; $x = 2; echo $txt; echo "<br>"; echo $x; echo “I love $txt"; echo”<br>”; echo ”I love”.$txt.”!”; ?> </body> </html>
  • 11. Constant in PHP A constant is name for a simple value. The value cannot be changed during the script. To create a constant, use the define() function. Syntex define(name, value, case-insensitive) Parameters: name: tell the name of the constant value: tell the value of the constant case-insensitive: tell whether the constant name is case-insensitive. Default is false
  • 12. Constant in PHP <?php define(“WELCOME", “to our office”,true); echo welcome; ?> <?php define(“WELCOME", “to our office”); echo WELCOME; ?> The example below creates a constant with a case-sensitive name: The example below creates a constant with a case-insensitive name: NOTE:Constants are automatically global and can be used inthe entire script.
  • 13. Differences between constants and variables  There is no need to write a dollar sign ($) before a constant, where as in Variable one has to write a dollar sign.  Constants cannot be defined by simple assignment, they may only be defined using the define() function.  Constants may be defined and accessed anywhere without regard to variable scoping rules.  Once the Constants have been set, may not be redefined or undefined.