SlideShare a Scribd company logo
P - PHP
H - Hypertext
P - Preprocessor
 PHP is an acronym for “PHP
Hypertext Preprocessor”. (Originally,
„Personal Home Page’). It was
created by Rasmus Lerdorf in 1995 to
maintain his personal home page
 PHP is a widely-used server scripting
language, and is a powerful tool for
making dynamic and interactive
web pages quickly
 PHP is an object-oriented
programming language, which
means that you can create objects,
which can contain variables and
functions
 PHP scripts are executed on the server
 PHP is an open source software
 PHP costs nothing, it is free to
download and use
PHP files can contain text, HTML,
CSS, JavaScript and PHP code
PHP files are executed on the
server and the result are returned
to the browser as plain HTML
PHP files have extension “.php”
To start using PHP, you can:
Find a web host with PHP and
MySQL Support
Install a web server on your own
PC, and then install PHP and
MySQL
Visit www.php.net for free download.
Download XAMPP installer
XAMPP is an all-in-one installer
package of local server, MySql
and PHP
* Take a look at this video on how to install XAMPP
1. Go to XAMPP directory folder
located in local disk C: & open it
2. Click the “htdocs” folder
3. Create your own folder inside
that „htdocs’
4. Put/save all your PHP Files inside
your own folder
*Remember: Never rename or delete any default folder/s
inside XAMPP directory except that of your own folder
*Take the ff. steps every time you want to
test/run your PHP files?
1. Open XAMPP Control Panel
2. Click the „Start‟ button of the Apache
Server and of the MySQL if your PHP has a
database
3. Open any web browser (Chrome,
IE,Firefox, Safari etc)
4. Type in the address bar
“localhost/yourfoldername” & press Enter
button
<?php
//php code goes here
?>
.php
Example: myfirstproject.php
File Name File Extension
<html>
<body>
<?php
echo "Hello World";
print “Hello World”;
?>
</body>
</html>
Example:
There are two basic statements to
output or send text to the browser:
echo or print
Example:
echo "Hello World";
print “Hello World”;
Each code line in PHP must end with a semicolon (;).
The semicolon is a separator and is used to
distinguish one set of instructions from another.
<html>
<body>
<?php
//This is a single line comment
# This is also a single line comment
/*
This is a multiple lines comment
block that spans over more than one line
*/
?>
</body>
</html>
Variables are “containers” for storing information. It
can store values like text strings, numbers or
arrays.
Rules for PHP variables:
 A variable starts with a $ (sigil) sign, followed by the
name of the variable.
 A variable name must start with a letter or the underscore
character
 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 ($y and $Y are two
different variables)
The correct way of declaring a variable in PHP:
$var_name = value;
Example:
<?php
$text="Hello Math!";
$x=5;
$y=6;
$z=$x+$y;
echo $z;
?>
Remember: (put quotes for text variable’s value)
(no quotes needed for number variable’s value)
 All user-defined functions, classes, and keywords
(e.g. if, else, while, echo, etc.) are case-
insensitive
Example 1:
<?php
EcHo “Hello World!”;
echo “Hello World!”;
ECHO “Hello World!”;
?>
all three echo
statements are
legal (and
equal)
 All variables are case-sensitive
Example:
<?php
$color=”red”;
echo “My car is “ . $color;
echo “My car is “ . $COLOR;
echo “My car is “ . $coLOR;
?>
only the first
statement will
display the
value of the
$color variable
( .) – Concatenator
The concatenation operator (.) is used to
put two string values together.
Example:
<?php
$txt1="Hello World!";
$txt2="What a nice day!";
echo $txt1 . " " . $txt2;
?>
The output of the code above will be:
Hello World! What a nice day!
Operators are used to operate on values.
Arithmetic Operators
Assignment Operators
Comparison Operators
Logical Operators
+ - * / % ++ --
= += -= *= /= .= %=
== != <> > < >= <=
&& and
II or
! not
Conditional Statements
The if...else Statement
Use the if....else statement to execute some code if a
condition is true and another code if a condition is false.
 Syntax
if (condition)
code to be executed if condition is true;
else
code to be executed if condition is false;
The if...else Statement
Example:
<html>
<body>
<?php
$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
else
echo "Have a nice day!";
?>
</body>
</html>
Conditional Statements
The if...elseif....else Statement
Use the if....elseif...else statement to select one of several
blocks of code to be executed.
 Syntax
if (condition)
code to be executed if condition is true;
elseif (condition)
code to be executed if condition is true;
else
code to be executed if condition is false;
The if...elseif....else Statement
Example:
<?php
$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
elseif ($d=="Sun")
echo "Have a nice Sunday!";
else
echo "Have a nice day!";
?>
Conditional statements are used to perform
different actions based on different conditions.
 Syntax
switch (n)
{
case label1:
code to be executed if n=label1;
break;
case label2:
code to be executed if n=label2;
break;
default:
code to be executed if n is different from both label1
and label2;
}
Example:
<?php
switch ($x)
{
case 1:
echo "Number 1";
break;
case 2:
echo "Number 2";
break;
case 3:
echo "Number 3";
break;
default:
echo "No number between 1 and 3";
}
?>
PHP $_POST Function
The built-in „$_POST‟ function is
used to collect values in a form
with method="post".
PHP $_POST Function
Example:
<form action="welcome.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
When the user clicks the "Submit" button, the
"welcome.php" file can now use the $_POST function to
collect form data
Welcome <?php echo $_POST["fname"]; ?>!<br />
You are <?php echo $_POST["age"]; ?> years old.
Output could be something like this:
Welcome John!
You are 28 years old.
Problem:
How to create a program that
inputs „student name‟,
„attendance grade‟, „quiz grade‟,
„project grade‟, & „major exam
grade‟ with an output of student
name, total grade and remarks
using PHP?
<html>
<body>
<h1> Student Grade:</h1>
<form action="compute.php" method="post">
Student Name:<input type="text" name="sname" />
<br>
Attendance Grade:<input type="text" name="agrade" />
<br>
Quiz Grade:<input type="text" name="qgrade" />
<br>
Project Grade: <input type="text" name="pgrade" />
<br>
Major Exam Grade:<input type="text" name="egrade" />
<br>
<input type="submit" value="Compute"/>
</form>
</body>
Create this first
file and Save
this as
studentgrade.
php
PHP file #1
<html>
<body>
<?php
echo $_POST["sname"];
?>
<br>
<?php
$attgrade = $_POST['agrade'];
$quizgrade = $_POST['qgrade'];
$prograde = $_POST['pgrade'];
$megrade = $_POST['egrade'];
$total = ($attgrade * 0.10) + ($quizgrade * 0.15) + ($prograde * 0.25)
+ ($megrade * 0.50);
?>
<br>
PHP file #2
<?php
echo 'Total Grade:' . $total;
?>
<br>
<?php
if ($total >= 75) {
echo "Remarks: Passed!";
}
else {
echo "Remarks: Failed!";
}
?>
</body>
</html>
Create this
second file
and Save this
as
compute.php
and run/test
the two files
Save this file as
compute.php
INPUT OUTPUT
THANK YOU!

More Related Content

What's hot

What's hot (20)

Php
PhpPhp
Php
 
Php Unit 1
Php Unit 1Php Unit 1
Php Unit 1
 
Constructor and encapsulation in php
Constructor and encapsulation in phpConstructor and encapsulation in php
Constructor and encapsulation in php
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
 
PHP Tutorials
PHP TutorialsPHP Tutorials
PHP Tutorials
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
Php introduction
Php introductionPhp introduction
Php introduction
 
PHP slides
PHP slidesPHP slides
PHP slides
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive Overview
 
Dev traning 2016 basics of PHP
Dev traning 2016   basics of PHPDev traning 2016   basics of PHP
Dev traning 2016 basics of PHP
 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
PHP MySQL Workshop - facehook
PHP MySQL Workshop - facehookPHP MySQL Workshop - facehook
PHP MySQL Workshop - facehook
 
PHP
PHPPHP
PHP
 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop Notes
 
PHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginnersPHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginners
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
 
php basics
php basicsphp basics
php basics
 
Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
 

Viewers also liked

pcb making in hindi pdf( पीसीबी बनाने की विधि हिंदी में )
pcb making in hindi pdf( पीसीबी बनाने की विधि हिंदी में )pcb making in hindi pdf( पीसीबी बनाने की विधि हिंदी में )
pcb making in hindi pdf( पीसीबी बनाने की विधि हिंदी में )
Chand Rook
 
Computer netwoking notes & qustionspart 2
Computer netwoking notes & qustionspart 2Computer netwoking notes & qustionspart 2
Computer netwoking notes & qustionspart 2
SirajRock
 
Photoshop hindi-notes
Photoshop hindi-notesPhotoshop hindi-notes
Photoshop hindi-notes
SirajRock
 
Excel shortcut and function keys hindi notes
Excel shortcut and function keys hindi notesExcel shortcut and function keys hindi notes
Excel shortcut and function keys hindi notes
SirajRock
 
Internet notes hindi
Internet notes hindiInternet notes hindi
Internet notes hindi
SirajRock
 
Introduction of Internet Hindi Notes
Introduction of Internet Hindi NotesIntroduction of Internet Hindi Notes
Introduction of Internet Hindi Notes
SirajRock
 
Microsoft office hindi notes
Microsoft office hindi notesMicrosoft office hindi notes
Microsoft office hindi notes
SirajRock
 
Corel draw 14 hindi notes
Corel draw 14 hindi notesCorel draw 14 hindi notes
Corel draw 14 hindi notes
SirajRock
 

Viewers also liked (16)

Pgdca final syllabus_2007_revised_31st_july_2007
Pgdca final syllabus_2007_revised_31st_july_2007Pgdca final syllabus_2007_revised_31st_july_2007
Pgdca final syllabus_2007_revised_31st_july_2007
 
Computer basic course
Computer basic courseComputer basic course
Computer basic course
 
pcb making in hindi pdf( पीसीबी बनाने की विधि हिंदी में )
pcb making in hindi pdf( पीसीबी बनाने की विधि हिंदी में )pcb making in hindi pdf( पीसीबी बनाने की विधि हिंदी में )
pcb making in hindi pdf( पीसीबी बनाने की विधि हिंदी में )
 
Router components in hindi
Router components in hindiRouter components in hindi
Router components in hindi
 
Pagemaker hindi notes
Pagemaker hindi notesPagemaker hindi notes
Pagemaker hindi notes
 
C language in hindi (cलेग्वेज इन हिंदी )
C language  in hindi (cलेग्वेज इन हिंदी )C language  in hindi (cलेग्वेज इन हिंदी )
C language in hindi (cलेग्वेज इन हिंदी )
 
Introduction To PHP
Introduction To PHPIntroduction To PHP
Introduction To PHP
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 
Computer netwoking notes & qustionspart 2
Computer netwoking notes & qustionspart 2Computer netwoking notes & qustionspart 2
Computer netwoking notes & qustionspart 2
 
Photoshop hindi-notes
Photoshop hindi-notesPhotoshop hindi-notes
Photoshop hindi-notes
 
Networking in hindi notes
Networking in hindi notesNetworking in hindi notes
Networking in hindi notes
 
Excel shortcut and function keys hindi notes
Excel shortcut and function keys hindi notesExcel shortcut and function keys hindi notes
Excel shortcut and function keys hindi notes
 
Internet notes hindi
Internet notes hindiInternet notes hindi
Internet notes hindi
 
Introduction of Internet Hindi Notes
Introduction of Internet Hindi NotesIntroduction of Internet Hindi Notes
Introduction of Internet Hindi Notes
 
Microsoft office hindi notes
Microsoft office hindi notesMicrosoft office hindi notes
Microsoft office hindi notes
 
Corel draw 14 hindi notes
Corel draw 14 hindi notesCorel draw 14 hindi notes
Corel draw 14 hindi notes
 

Similar to Php a dynamic web scripting language

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 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
 

Similar to Php a dynamic web scripting language (20)

Php
PhpPhp
Php
 
Basic php 5
Basic php 5Basic php 5
Basic php 5
 
Day1
Day1Day1
Day1
 
Php by shivitomer
Php by shivitomerPhp by shivitomer
Php by shivitomer
 
FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQL
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
PHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERSPHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERS
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
 
Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
 
Free PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in IndiaFree PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in India
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
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 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)
 
basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)
 
Intro to php
Intro to phpIntro to php
Intro to php
 
PHP - Web Development
PHP - Web DevelopmentPHP - Web Development
PHP - Web Development
 
PHP Hypertext Preprocessor
PHP Hypertext PreprocessorPHP Hypertext Preprocessor
PHP Hypertext Preprocessor
 

Recently uploaded

JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
Max Lee
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
Alluxio, Inc.
 

Recently uploaded (20)

Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 
JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
How To Build a Successful SaaS Design.pdf
How To Build a Successful SaaS Design.pdfHow To Build a Successful SaaS Design.pdf
How To Build a Successful SaaS Design.pdf
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Benefits of Employee Monitoring Software
Benefits of  Employee Monitoring SoftwareBenefits of  Employee Monitoring Software
Benefits of Employee Monitoring Software
 
A Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data MigrationA Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data Migration
 
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
 
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdfImplementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with StrimziStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi
 
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationA Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data Migration
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product UpdatesGraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
 
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 

Php a dynamic web scripting language

  • 1.
  • 2. P - PHP H - Hypertext P - Preprocessor
  • 3.  PHP is an acronym for “PHP Hypertext Preprocessor”. (Originally, „Personal Home Page’). It was created by Rasmus Lerdorf in 1995 to maintain his personal home page  PHP is a widely-used server scripting language, and is a powerful tool for making dynamic and interactive web pages quickly
  • 4.  PHP is an object-oriented programming language, which means that you can create objects, which can contain variables and functions  PHP scripts are executed on the server  PHP is an open source software  PHP costs nothing, it is free to download and use
  • 5. PHP files can contain text, HTML, CSS, JavaScript and PHP code PHP files are executed on the server and the result are returned to the browser as plain HTML PHP files have extension “.php”
  • 6. To start using PHP, you can: Find a web host with PHP and MySQL Support Install a web server on your own PC, and then install PHP and MySQL Visit www.php.net for free download.
  • 7. Download XAMPP installer XAMPP is an all-in-one installer package of local server, MySql and PHP * Take a look at this video on how to install XAMPP
  • 8.
  • 9. 1. Go to XAMPP directory folder located in local disk C: & open it 2. Click the “htdocs” folder 3. Create your own folder inside that „htdocs’ 4. Put/save all your PHP Files inside your own folder *Remember: Never rename or delete any default folder/s inside XAMPP directory except that of your own folder
  • 10. *Take the ff. steps every time you want to test/run your PHP files? 1. Open XAMPP Control Panel 2. Click the „Start‟ button of the Apache Server and of the MySQL if your PHP has a database 3. Open any web browser (Chrome, IE,Firefox, Safari etc) 4. Type in the address bar “localhost/yourfoldername” & press Enter button
  • 13. <html> <body> <?php echo "Hello World"; print “Hello World”; ?> </body> </html> Example:
  • 14. There are two basic statements to output or send text to the browser: echo or print Example: echo "Hello World"; print “Hello World”; Each code line in PHP must end with a semicolon (;). The semicolon is a separator and is used to distinguish one set of instructions from another.
  • 15. <html> <body> <?php //This is a single line comment # This is also a single line comment /* This is a multiple lines comment block that spans over more than one line */ ?> </body> </html>
  • 16. Variables are “containers” for storing information. It can store values like text strings, numbers or arrays. Rules for PHP variables:  A variable starts with a $ (sigil) sign, followed by the name of the variable.  A variable name must start with a letter or the underscore character  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 ($y and $Y are two different variables)
  • 17. The correct way of declaring a variable in PHP: $var_name = value; Example: <?php $text="Hello Math!"; $x=5; $y=6; $z=$x+$y; echo $z; ?> Remember: (put quotes for text variable’s value) (no quotes needed for number variable’s value)
  • 18.  All user-defined functions, classes, and keywords (e.g. if, else, while, echo, etc.) are case- insensitive Example 1: <?php EcHo “Hello World!”; echo “Hello World!”; ECHO “Hello World!”; ?> all three echo statements are legal (and equal)
  • 19.  All variables are case-sensitive Example: <?php $color=”red”; echo “My car is “ . $color; echo “My car is “ . $COLOR; echo “My car is “ . $coLOR; ?> only the first statement will display the value of the $color variable
  • 20. ( .) – Concatenator The concatenation operator (.) is used to put two string values together. Example: <?php $txt1="Hello World!"; $txt2="What a nice day!"; echo $txt1 . " " . $txt2; ?> The output of the code above will be: Hello World! What a nice day!
  • 21. Operators are used to operate on values. Arithmetic Operators Assignment Operators Comparison Operators Logical Operators + - * / % ++ -- = += -= *= /= .= %= == != <> > < >= <= && and II or ! not
  • 22. Conditional Statements The if...else Statement Use the if....else statement to execute some code if a condition is true and another code if a condition is false.  Syntax if (condition) code to be executed if condition is true; else code to be executed if condition is false;
  • 23. The if...else Statement Example: <html> <body> <?php $d=date("D"); if ($d=="Fri") echo "Have a nice weekend!"; else echo "Have a nice day!"; ?> </body> </html>
  • 24. Conditional Statements The if...elseif....else Statement Use the if....elseif...else statement to select one of several blocks of code to be executed.  Syntax if (condition) code to be executed if condition is true; elseif (condition) code to be executed if condition is true; else code to be executed if condition is false;
  • 25. The if...elseif....else Statement Example: <?php $d=date("D"); if ($d=="Fri") echo "Have a nice weekend!"; elseif ($d=="Sun") echo "Have a nice Sunday!"; else echo "Have a nice day!"; ?>
  • 26. Conditional statements are used to perform different actions based on different conditions.  Syntax switch (n) { case label1: code to be executed if n=label1; break; case label2: code to be executed if n=label2; break; default: code to be executed if n is different from both label1 and label2; }
  • 27. Example: <?php switch ($x) { case 1: echo "Number 1"; break; case 2: echo "Number 2"; break; case 3: echo "Number 3"; break; default: echo "No number between 1 and 3"; } ?>
  • 28. PHP $_POST Function The built-in „$_POST‟ function is used to collect values in a form with method="post".
  • 29. PHP $_POST Function Example: <form action="welcome.php" method="post"> Name: <input type="text" name="fname" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> When the user clicks the "Submit" button, the "welcome.php" file can now use the $_POST function to collect form data Welcome <?php echo $_POST["fname"]; ?>!<br /> You are <?php echo $_POST["age"]; ?> years old. Output could be something like this: Welcome John! You are 28 years old.
  • 30. Problem: How to create a program that inputs „student name‟, „attendance grade‟, „quiz grade‟, „project grade‟, & „major exam grade‟ with an output of student name, total grade and remarks using PHP?
  • 31. <html> <body> <h1> Student Grade:</h1> <form action="compute.php" method="post"> Student Name:<input type="text" name="sname" /> <br> Attendance Grade:<input type="text" name="agrade" /> <br> Quiz Grade:<input type="text" name="qgrade" /> <br> Project Grade: <input type="text" name="pgrade" /> <br> Major Exam Grade:<input type="text" name="egrade" /> <br> <input type="submit" value="Compute"/> </form> </body> Create this first file and Save this as studentgrade. php PHP file #1
  • 32. <html> <body> <?php echo $_POST["sname"]; ?> <br> <?php $attgrade = $_POST['agrade']; $quizgrade = $_POST['qgrade']; $prograde = $_POST['pgrade']; $megrade = $_POST['egrade']; $total = ($attgrade * 0.10) + ($quizgrade * 0.15) + ($prograde * 0.25) + ($megrade * 0.50); ?> <br> PHP file #2
  • 33. <?php echo 'Total Grade:' . $total; ?> <br> <?php if ($total >= 75) { echo "Remarks: Passed!"; } else { echo "Remarks: Failed!"; } ?> </body> </html> Create this second file and Save this as compute.php and run/test the two files
  • 34. Save this file as compute.php INPUT OUTPUT