SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Tech Pirates
Organized By Tech Pirates
Tech Pirates
Organized By Tech Pirates
What is PHP?
• PHP is an acronym for “Hypertext Preprocessor”
• PHP is a server scripting language, and a powerful tool for making dynamic
and interactive Web pages.
• PHP can be embedded into HTML
• PHP files have extension ".php"
Tech Pirates
Organized By Tech Pirates
Other server side technologies
1. ASP (Active Server Pages):
• This was Microsoft’s first server-side technology
• ASP programming code is interpreted at run time, hence it can be slow in comparison to other
technologies.
2. ASP.NET :
• This replaced Microsoft’s older ASP technology
• It is essentially limited to Windows servers
3. JSP (Java Server Pages)
4. Node.js
5. Perl
6. PHP
7. Python
8. Ruby on Rail
Tech Pirates
Organized By Tech Pirates
How server script will executes?
Tech Pirates
Organized By Tech Pirates
Sever scripts have access to many resources
like
Tech Pirates
Organized By Tech Pirates
• PHP can generate dynamic page content
• PHP can create, open, read, write, delete, and close files on the server
• PHP can collect form data
• PHP can add, delete, modify data in your database
What Can PHP Do?
Tech Pirates
Organized By Tech Pirates
• PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
• PHP is compatible with almost all servers used today (Apache, IIS, etc.)
• PHP supports a wide range of databases
• PHP is easy to learn and runs efficiently on the server side
Why PHP?
Tech Pirates
Organized By Tech Pirates
Market share of web development environments
Tech Pirates
Organized By Tech Pirates
• XAMPP or WAMP for Windows
• LAMP for Linux
• MAMP for Mac
Servers on various platforms
Installing XAMPP on Windows
You can download from this link
https://www.apachefriends.org/download.html
Tech Pirates
Organized By Tech Pirates
• A PHP script can be placed anywhere in the document.
• A PHP script starts with <?php and ends with ?>
<?php
// PHP code goes here
?>
• The default file extension for PHP files is ".php".
• A PHP file normally contains HTML tags, and some PHP scripting code.
Basic PHP Syntax
Tech Pirates
Organized By Tech Pirates
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello World!";
?>
</body>
</html>
First PHP script
Tech Pirates
Organized By Tech Pirates
In PHP, a variable starts with the $ sign, followed by the name of the
variable
<?php
$txt = “CIT”;
$x = 5;
$y = 10.5;
?>
Creating (Declaring) PHP Variables
Tech Pirates
Organized By Tech Pirates
Output Variables
• In PHP, there are 2 basic ways to get output: echo and print
• Small difference is echo has no return value and print has a return
value of 1.
<?php
$txt = “CIT";
$x = 5;
$y = 10.5;
echo "I love $txt!";
echo $x + $y;
?>
Tech Pirates
Organized By Tech Pirates
1. PHP String:
A string is a sequence of characters
<!DOCTYPE html>
<html>
<body>
<?php
$x = “CIT”;
$y = ‘CIT';
echo $x;
echo "<br>";
echo $y;
?>
</body>
</html>
PHP data types
Tech Pirates
Organized By Tech Pirates
2. PHP Integer:
An integer data type is a non-decimal number between -2,147,483,648 and 2,147,483,647.
Rules for integers:
• An integer must have at least one digit
• An integer must not have a decimal point
• An integer can be either positive or negative
<!DOCTYPE html>
<html>
<body>
<?php
$x = 2018;
echo $x;
var_dump($x); //var_dump() function returns the data type and value
?>
</body>
</html>
Tech Pirates
Organized By Tech Pirates
3. PHP Float:
A float (floating point number) is a number with a decimal point or a number in
exponential
<!DOCTYPE html>
<html>
<body>
<?php
$x = 3.142;
echo $x;
var_dump($x); //var_dump() function returns the data type and value
?>
</body>
</html>
Tech Pirates
Organized By Tech Pirates
4. PHP Array:
An array stores multiple values in one single variable.
<!DOCTYPE html>
<html>
<body>
<?php
$cars = array("Volvo","BMW","Toyota");
var_dump($cars);
?>
</body>
</html>
Tech Pirates
Organized By Tech Pirates
PHP Conditional Statements
PHP - The if Statement:
The if statement executes some code if one condition is true.
Syntax
if (condition)
{
//code to be executed if condition is true;
}
Example
<?php
$t = date(“h");
if ($t < “10") {
echo "Have a good day!";
}
?>
Tech Pirates
Organized By Tech Pirates
PHP - The if else Statement:
The if else statement executes some code if a condition is true and another code if
that condition is false.
Syntax
if (condition)
{
code to be executed if condition is true;
}
else
{
code to be executed if condition is false;
}
Example
<?php
$t = date("H");
if ($t < "20")
{
echo "Have a good day!";
}
else
{
echo "Have a good night!";
}
?>
Tech Pirates
Organized By Tech Pirates
PHP - The if elseif else Statement:
It executes different codes for more than two conditions.
Syntax
if (condition)
{
code to be executed if this condition is true;
}
elseif (condition)
{
code to be executed if this condition is true;
}
else
{
code to be executed if all conditions are false;
}
Example
<?php
$t = date("H");
if ($t < "10")
{
echo "Have a good morning!";
}
elseif ($t < "20")
{
echo "Have a good day!";
}
else
{
echo "Have a good night!";
}
?>
Tech Pirates
Organized By Tech Pirates
The for loop is used when you know in advance how many times the script should
run.
PHP for Loops
Syntax
for (init counter; test counter; increment counter)
{
code to be executed;
}
Example
<?php
for ($i = 0; $i <= 10; $i++) {
echo "The number is: $i <br>";
}
?>
Tech Pirates
Organized By Tech Pirates
PHP Form Handling
Welcome.html
<html>
<body>
<form action="welcome.php" method="post">
Name : <input type="text" name="name"><br>
E-mail : <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
welcome.php
<!DOCTYPE HTML>
<html>
<body>
<?php echo "Welcome ".$_POST["name"]; ?><br>
<?php echo "Your email address is
".$_POST["email"]; ?>
</body>
</html>
Tech Pirates
Organized By Tech Pirates

Weitere ähnliche Inhalte

Was ist angesagt? (20)

PHP, Under The Hood - DPC
PHP, Under The Hood - DPCPHP, Under The Hood - DPC
PHP, Under The Hood - DPC
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive Overview
 
Php introduction
Php introductionPhp introduction
Php introduction
 
Php(report)
Php(report)Php(report)
Php(report)
 
Php hypertext pre-processor
Php   hypertext pre-processorPhp   hypertext pre-processor
Php hypertext pre-processor
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Intro to php
Intro to phpIntro to php
Intro to php
 
php_tizag_tutorial
php_tizag_tutorialphp_tizag_tutorial
php_tizag_tutorial
 
PHP
PHPPHP
PHP
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Php internal architecture
Php internal architecturePhp internal architecture
Php internal architecture
 
Prersentation
PrersentationPrersentation
Prersentation
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
 
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 Ppt
Php PptPhp Ppt
Php Ppt
 
Phpbasics
PhpbasicsPhpbasics
Phpbasics
 
Php basics
Php basicsPhp basics
Php basics
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
What Is Php
What Is PhpWhat Is Php
What Is Php
 

Ähnlich wie Php

Ähnlich wie Php (20)

Basics PHP
Basics PHPBasics PHP
Basics PHP
 
Php
PhpPhp
Php
 
Intro to-php-19 jun10
Intro to-php-19 jun10Intro to-php-19 jun10
Intro to-php-19 jun10
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)
 
Wt unit 4 server side technology-2
Wt unit 4 server side technology-2Wt unit 4 server side technology-2
Wt unit 4 server side technology-2
 
PHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERSPHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERS
 
Php training100%placement-in-mumbai
Php training100%placement-in-mumbaiPhp training100%placement-in-mumbai
Php training100%placement-in-mumbai
 
php basics
php basicsphp basics
php basics
 
Php unit i
Php unit iPhp unit i
Php unit i
 
PHP MySQL Workshop - facehook
PHP MySQL Workshop - facehookPHP MySQL Workshop - facehook
PHP MySQL Workshop - facehook
 
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...
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Php intro
Php introPhp intro
Php intro
 
Desktop Apps with PHP and Titanium
Desktop Apps with PHP and TitaniumDesktop Apps with PHP and Titanium
Desktop Apps with PHP and Titanium
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 

Kürzlich hochgeladen

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
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projectssmsksolar
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfRagavanV2
 
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
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 

Kürzlich hochgeladen (20)

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
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
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
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 

Php

  • 2. Tech Pirates Organized By Tech Pirates What is PHP? • PHP is an acronym for “Hypertext Preprocessor” • PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. • PHP can be embedded into HTML • PHP files have extension ".php"
  • 3. Tech Pirates Organized By Tech Pirates Other server side technologies 1. ASP (Active Server Pages): • This was Microsoft’s first server-side technology • ASP programming code is interpreted at run time, hence it can be slow in comparison to other technologies. 2. ASP.NET : • This replaced Microsoft’s older ASP technology • It is essentially limited to Windows servers 3. JSP (Java Server Pages) 4. Node.js 5. Perl 6. PHP 7. Python 8. Ruby on Rail
  • 4. Tech Pirates Organized By Tech Pirates How server script will executes?
  • 5. Tech Pirates Organized By Tech Pirates Sever scripts have access to many resources like
  • 6. Tech Pirates Organized By Tech Pirates • PHP can generate dynamic page content • PHP can create, open, read, write, delete, and close files on the server • PHP can collect form data • PHP can add, delete, modify data in your database What Can PHP Do?
  • 7. Tech Pirates Organized By Tech Pirates • PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.) • PHP is compatible with almost all servers used today (Apache, IIS, etc.) • PHP supports a wide range of databases • PHP is easy to learn and runs efficiently on the server side Why PHP?
  • 8. Tech Pirates Organized By Tech Pirates Market share of web development environments
  • 9. Tech Pirates Organized By Tech Pirates • XAMPP or WAMP for Windows • LAMP for Linux • MAMP for Mac Servers on various platforms Installing XAMPP on Windows You can download from this link https://www.apachefriends.org/download.html
  • 10. Tech Pirates Organized By Tech Pirates • A PHP script can be placed anywhere in the document. • A PHP script starts with <?php and ends with ?> <?php // PHP code goes here ?> • The default file extension for PHP files is ".php". • A PHP file normally contains HTML tags, and some PHP scripting code. Basic PHP Syntax
  • 11. Tech Pirates Organized By Tech Pirates <html> <body> <h1>My first PHP page</h1> <?php echo "Hello World!"; ?> </body> </html> First PHP script
  • 12. Tech Pirates Organized By Tech Pirates In PHP, a variable starts with the $ sign, followed by the name of the variable <?php $txt = “CIT”; $x = 5; $y = 10.5; ?> Creating (Declaring) PHP Variables
  • 13. Tech Pirates Organized By Tech Pirates Output Variables • In PHP, there are 2 basic ways to get output: echo and print • Small difference is echo has no return value and print has a return value of 1. <?php $txt = “CIT"; $x = 5; $y = 10.5; echo "I love $txt!"; echo $x + $y; ?>
  • 14. Tech Pirates Organized By Tech Pirates 1. PHP String: A string is a sequence of characters <!DOCTYPE html> <html> <body> <?php $x = “CIT”; $y = ‘CIT'; echo $x; echo "<br>"; echo $y; ?> </body> </html> PHP data types
  • 15. Tech Pirates Organized By Tech Pirates 2. PHP Integer: An integer data type is a non-decimal number between -2,147,483,648 and 2,147,483,647. Rules for integers: • An integer must have at least one digit • An integer must not have a decimal point • An integer can be either positive or negative <!DOCTYPE html> <html> <body> <?php $x = 2018; echo $x; var_dump($x); //var_dump() function returns the data type and value ?> </body> </html>
  • 16. Tech Pirates Organized By Tech Pirates 3. PHP Float: A float (floating point number) is a number with a decimal point or a number in exponential <!DOCTYPE html> <html> <body> <?php $x = 3.142; echo $x; var_dump($x); //var_dump() function returns the data type and value ?> </body> </html>
  • 17. Tech Pirates Organized By Tech Pirates 4. PHP Array: An array stores multiple values in one single variable. <!DOCTYPE html> <html> <body> <?php $cars = array("Volvo","BMW","Toyota"); var_dump($cars); ?> </body> </html>
  • 18. Tech Pirates Organized By Tech Pirates PHP Conditional Statements PHP - The if Statement: The if statement executes some code if one condition is true. Syntax if (condition) { //code to be executed if condition is true; } Example <?php $t = date(“h"); if ($t < “10") { echo "Have a good day!"; } ?>
  • 19. Tech Pirates Organized By Tech Pirates PHP - The if else Statement: The if else statement executes some code if a condition is true and another code if that condition is false. Syntax if (condition) { code to be executed if condition is true; } else { code to be executed if condition is false; } Example <?php $t = date("H"); if ($t < "20") { echo "Have a good day!"; } else { echo "Have a good night!"; } ?>
  • 20. Tech Pirates Organized By Tech Pirates PHP - The if elseif else Statement: It executes different codes for more than two conditions. Syntax if (condition) { code to be executed if this condition is true; } elseif (condition) { code to be executed if this condition is true; } else { code to be executed if all conditions are false; } Example <?php $t = date("H"); if ($t < "10") { echo "Have a good morning!"; } elseif ($t < "20") { echo "Have a good day!"; } else { echo "Have a good night!"; } ?>
  • 21. Tech Pirates Organized By Tech Pirates The for loop is used when you know in advance how many times the script should run. PHP for Loops Syntax for (init counter; test counter; increment counter) { code to be executed; } Example <?php for ($i = 0; $i <= 10; $i++) { echo "The number is: $i <br>"; } ?>
  • 22. Tech Pirates Organized By Tech Pirates PHP Form Handling Welcome.html <html> <body> <form action="welcome.php" method="post"> Name : <input type="text" name="name"><br> E-mail : <input type="text" name="email"><br> <input type="submit"> </form> </body> </html> welcome.php <!DOCTYPE HTML> <html> <body> <?php echo "Welcome ".$_POST["name"]; ?><br> <?php echo "Your email address is ".$_POST["email"]; ?> </body> </html>