SlideShare a Scribd company logo
Salient features of PHP
Developed by
Dr.Sm.Badhusha
Prof/CSE, AIET
Goals of the session 1 & 2
Understanding the salient features of PHP
Learning important programming constructs
Comprehending the example codes in PHP
Working out the illustrative programs
individually

PHP == ‘ PHP Hypertext Preprocessor’

Open-source programming script

Server-side scripting language

Executed on the server-side

Used to generate dynamic web-pages
Why PHP Is a Great
Programming Language?
Fast Load Time – PHP results in faster site loading speeds
compared ASP .NET
Less Expensive Software - Open source software
Simple & Easy to Grab (similar to C and Java to an extent)
Flexibility & Free ( not restricted to one type of apps, open
source)
Integration (integrating multiple web applications)
Scalability ( enhancing your cluster size by adding servers)
Quality Support ( from global community)

PHP scripts reside between reserved PHP tags
<?PHP ….?>

This allows the programmer to embed PHP
scripts within HTML pages

Interpreted language, scripts are parsed at
run-time rather than compiled beforehand

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
…
?>
Embedding PHP in Web pages
XML Style
<?php echo “Hello , World !”; ?>
SGML style
<? echo “Hello , World !”; ?>
Hello.php
RUNNING PHP FILE ON APACHE
By default Apache is using /var/www/html
default directory
Using Linux OS
save it in
/var/www/html/file.php
Using Xamp server in windows OS, save it in
xamp/htdocs/foldername/file.php
Now you can execute the file by running the
browser with
http://localhost/file.php
To check Apache is running on the system
http://localhost/
Apache page will be downloaded
Sample program hello.php
<html>
<head>
<title>Example</title>
</head>
<body>
<?php
echo "Hi, Hello, I'm a PHP script!";
?>
</body>
</html>
Demo: hello.php
Comments in PHP
 Standard C, C++, and shell comment
symbols
// C++ and Java-style comment
# Shell-style comments
/* C-style comments
These can span multiple lines */
Variables in PHP
 PHP variables must begin with a “$” sign
 Case-sensitive ($Foo != $foo != $fOo)
 Global and locally-scoped variables
 Global variables can be used anywhere
 Local variables restricted to a function or class
 Certain variable names reserved by PHP
 Form variables ($_POST, $_GET)
 Server variables ($_SERVER)
 Etc.
Variable usage
<?php
$foo = 25; // Numerical variable
$bar = “Hello”; // String variable
$foo = ($foo * 7); // Multiplies foo by 7
$bar = ($bar * 7); // Invalid expression
?>
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=$foo’ outputs $foo 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
$foo = 25; // Numerical variable
$bar = “Hello”; // String variable
echo $bar; // Outputs
echo $foo,$bar; // Outputs
echo “5x5=”,$foo; // Outputs
echo “5x5=$foo”; // Outputs
echo ‘5x5=$foo’; // Outputs
?>
Arithmetic Operations
 $a - $b // subtraction
 $a * $b // multiplication
 $a / $b // division
 $a += 5 // $a = $a+5 Also works for *= and /=
<?php
$a=15;
$b=30;
$total=$a+$b;
Print $total;
Print “<p><h1>$total</h1>”;
// total is 45
?>
Concatenation
 Use a period to join strings into one.
<?php
$string1=“Hello”;
$string2=“PHP”;
$string3=$string1 . “ ” .
$string2;
Print $string3;
?>
Hello PHP
PHP Control Structures
 Control Structures: Are the structures within a language
that allow us to control the flow of execution through a
program or script.
 Grouped into conditional (branching) structures (e.g.
if/else) and repetition structures (e.g. while loops).
 Example if/else if/else statement:
if ($foo == 0) {
echo ‘The variable foo is equal to 0’;
}
else if (($foo > 0) && ($foo <= 5)) {
echo ‘The variable foo is between 1 and 5’;
}
else {
echo ‘The variable foo is equal to ‘.$foo;
}
If ... Else...
 If (condition)
{
Statements;
}
Else
{
Statement;
}
<?php
If($user==“John”)
{
Print “Hello John.”;
}
Else
{
Print “You are not John.”;
}
?>
No THEN in PHP
While Loops
 While (condition)
{
Statements;
}
<?php
$count=0;
While($count<3)
{
Print “hello PHP. ”;
$count += 1;
// $count = $count + 1;
// or
// $count++;
?>
hello PHP. hello PHP. hello PHP.
Switch case
switch($name) {
case ‘rasmus’ :
// do something
break;
case ‘bob’ :
// do something
break;
case ‘bob1’ :
// do something
break;
case ‘bob2’ :
// do something
break;
default :
// do some thing
break;
}
for( ), foreach()
$total=0;
for($i=1;$i<=10;$i++) {
$total+=$i;
}
$person=array(‘Edison’, ‘Wankel’, ‘Crapper’);
foreach($person as $name){
echo “Hello, $name<br>” ;
}
Implicit Casting
 The conversion of a value from one type to
another is called casting
 Type juggling is called implicit casting
 Rules for type juggling are
 Type of 1st
operand Type of 2nd
operand conversion
Integer Floating int to float
integer String str to integer
float string str to float
Type Juggling
• $foo = "0"; // $foo is string (ASCII 48)
• $foo += 2; // $foo is now an integer (2)
• $foo = $foo + 1.3; // $foo is now a float (3.3)
• $foo = 5 + "10 Pieces "; // $foo is integer (15)
$foo = 5 + "Pieces 15";
Escaping the Character
 If the string has a set of double quotation
marks that must remain visible, use the 
[backslash] before the quotation marks to
ignore and display them.
<?php
$heading=“”Computer Science””;
Print $heading;
?>
“Computer Science”
Data Types
Integers (-2,147,483,648 to (2,147,483,647)
Floating Point no (3.14, .314E1, 17.0E-3)
Strings can be represented as
‘big dog’ or
“fat cat”
Variables are expanded within double quotes while within
single quotes they are not
$name=“Ram”
Echo ‘hi,$name’
o/p : hi,$name
echo “hi,$name”
o/p : hi,Ram (Demo: function.php)
Variables
Identified prefix with $ sign
Variable Variables
A variable whose name is stored in
another variable
$foo=‘bar’;

More Related Content

Similar to PHP Programming and its Applications workshop (20)

My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
omprakash_bagrao_prdxn
 
Php mysql
Php mysqlPhp mysql
Php mysql
Alebachew Zewdu
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
Nidhi mishra
 
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
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
Lecture 6: Introduction to PHP and Mysql .pptx
Lecture 6:  Introduction to PHP and Mysql .pptxLecture 6:  Introduction to PHP and Mysql .pptx
Lecture 6: Introduction to PHP and Mysql .pptx
AOmaAli
 
Day1
Day1Day1
Day1
IRWAA LLC
 
Php introduction
Php introductionPhp introduction
Php introduction
krishnapriya Tadepalli
 
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)
Muhamad Al Imran
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
Muhamad Al Imran
 
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)
Muhamad Al Imran
 
Php mysql
Php mysqlPhp mysql
Php mysql
Shehrevar Davierwala
 
introduction to server-side scripting
introduction to server-side scriptingintroduction to server-side scripting
introduction to server-side scripting
Amirul Shafeeq
 
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...
anshkhurana01
 
Php intro by sami kz
Php intro by sami kzPhp intro by sami kz
Php intro by sami kz
sami2244
 
Intro to php
Intro to phpIntro to php
Intro to php
Ahmed Farag
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
baabtra.com - No. 1 supplier of quality freshers
 
Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1
Gheyath M. Othman
 
PHP - Web Development
PHP - Web DevelopmentPHP - Web Development
PHP - Web Development
Niladri Karmakar
 
Programming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th SemesterProgramming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th Semester
SanthiNivas
 
Php Unit 1
Php Unit 1Php Unit 1
Php Unit 1
team11vgnt
 
Lecture 6: Introduction to PHP and Mysql .pptx
Lecture 6:  Introduction to PHP and Mysql .pptxLecture 6:  Introduction to PHP and Mysql .pptx
Lecture 6: Introduction to PHP and Mysql .pptx
AOmaAli
 
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)
Muhamad Al Imran
 
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)
Muhamad Al Imran
 
introduction to server-side scripting
introduction to server-side scriptingintroduction to server-side scripting
introduction to server-side scripting
Amirul Shafeeq
 
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...
anshkhurana01
 
Php intro by sami kz
Php intro by sami kzPhp intro by sami kz
Php intro by sami kz
sami2244
 
Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1
Gheyath M. Othman
 
Programming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th SemesterProgramming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th Semester
SanthiNivas
 

More from S.Mohideen Badhusha (7)

Introduction to Python Data Analytics.pdf
Introduction to Python Data Analytics.pdfIntroduction to Python Data Analytics.pdf
Introduction to Python Data Analytics.pdf
S.Mohideen Badhusha
 
Simple intro to HTML and its applications
Simple intro to HTML and its applicationsSimple intro to HTML and its applications
Simple intro to HTML and its applications
S.Mohideen Badhusha
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
Object oriented Programming using C++ and Java
Object oriented Programming using C++ and JavaObject oriented Programming using C++ and Java
Object oriented Programming using C++ and Java
S.Mohideen Badhusha
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
Introduction to Python Data Analytics.pdf
Introduction to Python Data Analytics.pdfIntroduction to Python Data Analytics.pdf
Introduction to Python Data Analytics.pdf
S.Mohideen Badhusha
 
Simple intro to HTML and its applications
Simple intro to HTML and its applicationsSimple intro to HTML and its applications
Simple intro to HTML and its applications
S.Mohideen Badhusha
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
Object oriented Programming using C++ and Java
Object oriented Programming using C++ and JavaObject oriented Programming using C++ and Java
Object oriented Programming using C++ and Java
S.Mohideen Badhusha
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
Ad

Recently uploaded (20)

SEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair KitSEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair Kit
projectultramechanix
 
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptxFINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
kippcam
 
11th International Conference on Data Mining (DaMi 2025)
11th International Conference on Data Mining (DaMi 2025)11th International Conference on Data Mining (DaMi 2025)
11th International Conference on Data Mining (DaMi 2025)
kjim477n
 
A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...
A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...
A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...
ijfcstjournal
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
Impurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptxImpurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptx
dhanashree78
 
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
Journal of Soft Computing in Civil Engineering
 
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghjfHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
yadavshivank2006
 
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) ProjectMontreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Alexandra N. Martinez
 
Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401
Unknown
 
Artificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowyArtificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowy
dominikamizerska1
 
Présentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptxPrésentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptx
KHADIJAESSAKET
 
ACEP Magazine Fifth Edition on 5june2025
ACEP Magazine Fifth Edition on 5june2025ACEP Magazine Fifth Edition on 5june2025
ACEP Magazine Fifth Edition on 5june2025
Rahul
 
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journeyRigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Yannis
 
Structural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant ConversionStructural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant Conversion
DanielRoman285499
 
Third Review PPT that consists of the project d etails like abstract.
Third Review PPT that consists of the project d etails like abstract.Third Review PPT that consists of the project d etails like abstract.
Third Review PPT that consists of the project d etails like abstract.
Sowndarya6
 
New Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docxNew Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docx
misheetasah
 
Introduction to AI agent development with MCP
Introduction to AI agent development with MCPIntroduction to AI agent development with MCP
Introduction to AI agent development with MCP
Dori Waldman
 
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptxWeek 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
dayananda54
 
Computer_vision-photometric_image_formation.pdf
Computer_vision-photometric_image_formation.pdfComputer_vision-photometric_image_formation.pdf
Computer_vision-photometric_image_formation.pdf
kumarprem6767merp
 
SEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair KitSEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair Kit
projectultramechanix
 
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptxFINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
kippcam
 
11th International Conference on Data Mining (DaMi 2025)
11th International Conference on Data Mining (DaMi 2025)11th International Conference on Data Mining (DaMi 2025)
11th International Conference on Data Mining (DaMi 2025)
kjim477n
 
A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...
A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...
A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...
ijfcstjournal
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
Impurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptxImpurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptx
dhanashree78
 
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghjfHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
yadavshivank2006
 
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) ProjectMontreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Alexandra N. Martinez
 
Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401
Unknown
 
Artificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowyArtificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowy
dominikamizerska1
 
Présentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptxPrésentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptx
KHADIJAESSAKET
 
ACEP Magazine Fifth Edition on 5june2025
ACEP Magazine Fifth Edition on 5june2025ACEP Magazine Fifth Edition on 5june2025
ACEP Magazine Fifth Edition on 5june2025
Rahul
 
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journeyRigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Yannis
 
Structural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant ConversionStructural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant Conversion
DanielRoman285499
 
Third Review PPT that consists of the project d etails like abstract.
Third Review PPT that consists of the project d etails like abstract.Third Review PPT that consists of the project d etails like abstract.
Third Review PPT that consists of the project d etails like abstract.
Sowndarya6
 
New Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docxNew Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docx
misheetasah
 
Introduction to AI agent development with MCP
Introduction to AI agent development with MCPIntroduction to AI agent development with MCP
Introduction to AI agent development with MCP
Dori Waldman
 
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptxWeek 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
dayananda54
 
Computer_vision-photometric_image_formation.pdf
Computer_vision-photometric_image_formation.pdfComputer_vision-photometric_image_formation.pdf
Computer_vision-photometric_image_formation.pdf
kumarprem6767merp
 
Ad

PHP Programming and its Applications workshop

  • 1. Salient features of PHP Developed by Dr.Sm.Badhusha Prof/CSE, AIET
  • 2. Goals of the session 1 & 2 Understanding the salient features of PHP Learning important programming constructs Comprehending the example codes in PHP Working out the illustrative programs individually
  • 3.  PHP == ‘ PHP Hypertext Preprocessor’  Open-source programming script  Server-side scripting language  Executed on the server-side  Used to generate dynamic web-pages
  • 4. Why PHP Is a Great Programming Language? Fast Load Time – PHP results in faster site loading speeds compared ASP .NET Less Expensive Software - Open source software Simple & Easy to Grab (similar to C and Java to an extent) Flexibility & Free ( not restricted to one type of apps, open source) Integration (integrating multiple web applications) Scalability ( enhancing your cluster size by adding servers) Quality Support ( from global community)
  • 5.  PHP scripts reside between reserved PHP tags <?PHP ….?>  This allows the programmer to embed PHP scripts within HTML pages  Interpreted language, scripts are parsed at run-time rather than compiled beforehand  Various built-in functions allow for fast development  Compatible with many popular databases
  • 6. 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 … ?>
  • 7. Embedding PHP in Web pages XML Style <?php echo “Hello , World !”; ?> SGML style <? echo “Hello , World !”; ?> Hello.php
  • 8. RUNNING PHP FILE ON APACHE By default Apache is using /var/www/html default directory Using Linux OS save it in /var/www/html/file.php Using Xamp server in windows OS, save it in xamp/htdocs/foldername/file.php Now you can execute the file by running the browser with http://localhost/file.php To check Apache is running on the system http://localhost/ Apache page will be downloaded
  • 9. Sample program hello.php <html> <head> <title>Example</title> </head> <body> <?php echo "Hi, Hello, I'm a PHP script!"; ?> </body> </html> Demo: hello.php
  • 10. Comments in PHP  Standard C, C++, and shell comment symbols // C++ and Java-style comment # Shell-style comments /* C-style comments These can span multiple lines */
  • 11. Variables in PHP  PHP variables must begin with a “$” sign  Case-sensitive ($Foo != $foo != $fOo)  Global and locally-scoped variables  Global variables can be used anywhere  Local variables restricted to a function or class  Certain variable names reserved by PHP  Form variables ($_POST, $_GET)  Server variables ($_SERVER)  Etc.
  • 12. Variable usage <?php $foo = 25; // Numerical variable $bar = “Hello”; // String variable $foo = ($foo * 7); // Multiplies foo by 7 $bar = ($bar * 7); // Invalid expression ?>
  • 13. 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
  • 14. Echo example  Notice how echo ‘5x5=$foo’ outputs $foo 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 $foo = 25; // Numerical variable $bar = “Hello”; // String variable echo $bar; // Outputs echo $foo,$bar; // Outputs echo “5x5=”,$foo; // Outputs echo “5x5=$foo”; // Outputs echo ‘5x5=$foo’; // Outputs ?>
  • 15. Arithmetic Operations  $a - $b // subtraction  $a * $b // multiplication  $a / $b // division  $a += 5 // $a = $a+5 Also works for *= and /= <?php $a=15; $b=30; $total=$a+$b; Print $total; Print “<p><h1>$total</h1>”; // total is 45 ?>
  • 16. Concatenation  Use a period to join strings into one. <?php $string1=“Hello”; $string2=“PHP”; $string3=$string1 . “ ” . $string2; Print $string3; ?> Hello PHP
  • 17. PHP Control Structures  Control Structures: Are the structures within a language that allow us to control the flow of execution through a program or script.  Grouped into conditional (branching) structures (e.g. if/else) and repetition structures (e.g. while loops).  Example if/else if/else statement: if ($foo == 0) { echo ‘The variable foo is equal to 0’; } else if (($foo > 0) && ($foo <= 5)) { echo ‘The variable foo is between 1 and 5’; } else { echo ‘The variable foo is equal to ‘.$foo; }
  • 18. If ... Else...  If (condition) { Statements; } Else { Statement; } <?php If($user==“John”) { Print “Hello John.”; } Else { Print “You are not John.”; } ?> No THEN in PHP
  • 19. While Loops  While (condition) { Statements; } <?php $count=0; While($count<3) { Print “hello PHP. ”; $count += 1; // $count = $count + 1; // or // $count++; ?> hello PHP. hello PHP. hello PHP.
  • 20. Switch case switch($name) { case ‘rasmus’ : // do something break; case ‘bob’ : // do something break; case ‘bob1’ : // do something break; case ‘bob2’ : // do something break; default : // do some thing break; }
  • 21. for( ), foreach() $total=0; for($i=1;$i<=10;$i++) { $total+=$i; } $person=array(‘Edison’, ‘Wankel’, ‘Crapper’); foreach($person as $name){ echo “Hello, $name<br>” ; }
  • 22. Implicit Casting  The conversion of a value from one type to another is called casting  Type juggling is called implicit casting  Rules for type juggling are  Type of 1st operand Type of 2nd operand conversion Integer Floating int to float integer String str to integer float string str to float
  • 23. Type Juggling • $foo = "0"; // $foo is string (ASCII 48) • $foo += 2; // $foo is now an integer (2) • $foo = $foo + 1.3; // $foo is now a float (3.3) • $foo = 5 + "10 Pieces "; // $foo is integer (15) $foo = 5 + "Pieces 15";
  • 24. Escaping the Character  If the string has a set of double quotation marks that must remain visible, use the [backslash] before the quotation marks to ignore and display them. <?php $heading=“”Computer Science””; Print $heading; ?> “Computer Science”
  • 25. Data Types Integers (-2,147,483,648 to (2,147,483,647) Floating Point no (3.14, .314E1, 17.0E-3) Strings can be represented as ‘big dog’ or “fat cat” Variables are expanded within double quotes while within single quotes they are not $name=“Ram” Echo ‘hi,$name’ o/p : hi,$name echo “hi,$name” o/p : hi,Ram (Demo: function.php)
  • 26. Variables Identified prefix with $ sign Variable Variables A variable whose name is stored in another variable $foo=‘bar’;