SlideShare a Scribd company logo
PHP : Hypertext Preprocessor
What is PHP?
 PHP stands for PHP: Hypertext Preprocessor
 PHP is a widely-used, open source scripting
language
 PHP scripts are executed on the server
 PHP is free to download and use
What is a PHP File?
 PHP files can contain text, HTML, JavaScript code,
and PHP code
 PHP code are executed on the server, and the result
is returned to the browser as plain HTML
 PHP files have a default file extension of ".php"
What Can PHP Do?
 PHP can generate dynamic page content
 PHP can create, open, read, write, and close files on
the server
 PHP can collect form data
 PHP can send and receive cookies
 PHP can add, delete, modify data in your database
 PHP can restrict users to access some pages on
your website
 PHP can encrypt data
Why PHP?
 PHP runs on different platforms (Windows, Linux,
Unix, Mac OS X, etc.)
 PHP is compatible with almost all servers used today
(Apache, IIS, etc.)
 PHP has support for a wide range of databases
 PHP is free. Download it from the official PHP
resource: www.php.net
 PHP is easy to learn and runs efficiently on the
server side
Set Up PHP on Your Own PC
 However, if your server does not support PHP, you
must:
 install a web server
 install PHP
 install a database, such as MySQL
 The official PHP website (PHP.net) has installation
instructions for
PHP: http://php.net/manual/en/install.php
Basic PHP Syntax
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".
Comments in PHP
 Example
<html>
<body>
<?php
//This is a PHP comment line
/*
This is a PHP comment
block
*/
?>
</body>
</html>
PHP Variables
 Variable can have short names (like x and y) or more
descriptive names (age, carname, totalvolume).
 Rules for PHP variables:
 A variable starts with the $ sign, followed by the name of
the variable
 A variable name must begin with a letter or the
underscore character
 A variable name can only contain alpha-numeric
characters and underscores (A-z, 0-9, and _ )
 A variable name should not contain spaces
 Variable names are case sensitive ($y and $Y are two
different variables)
Creating (Declaring) PHP Variables
 PHP has no command for declaring a variable.
 A variable is created the moment you first assign a
value to it:
 $txt="Hello world!";
$x=5;
 After the execution of the statements above, the
variable txt will hold the value Hello world!, and the
variable xwill hold the value 5.
 Note: When you assign a text value to a variable,
put quotes around the value.
PHP is a Loosely Typed Language
 In the example above, notice that we did not have to
tell PHP which data type the variable is.
 PHP automatically converts the variable to the
correct data type, depending on its value.
 In a strongly typed programming language, we will
have to declare (define) the type and name of the
variable before using it.
PHP Variable Scopes
 The scope of a variable is the part of the script
where the variable can be referenced/used.
 PHP has four different variable scopes:
 local
 global
 static
 parameter
Local Scope
 A variable declared within a PHP function is local
and can only be accessed within that function:
 Example
<?php
$x=5; // global scope
function myTest()
{
echo $x; // local scope
}
myTest();
?>
Global Scope
 A variable that is defined outside of any function, has
a global scope.
 Global variables can be accessed from any part of
the script, EXCEPT from within a function.
 To access a global variable from within a function,
use the global keyword:
Global Scope
 Example
 <?php
$x=5; // global scope
$y=10; // global scope
function myTest()
{
global $x,$y;
$y=$x+$y;
}
myTest();
echo $y; // outputs 15
?>
Static Scope
 When a function is completed, all of its variables are
normally deleted. However, sometimes you want a
local variable to not be deleted.
 To do this, use the static keyword when you first
declare the variable:
Static Scope
 Example
<?php
function myTest()
{
static $x=0;
echo $x;
$x++;
}
myTest();
myTest();
myTest();
?>
 OUTPUT ?
Parameter Scope
 A parameter is a local variable whose value is
passed to the function by the calling code.
 Parameters are declared in a parameter list as part
of the function declaration:
 Example : <?php
function myTest($x)
{
echo $x;
}
myTest(5);
?>
PHP echo and print Statements
 In PHP there is two basic ways to get output:
echo and print.
 There are some differences between echo and
print:
 echo - can output one or more strings
 print - can only output one string, and returns always 1
 Tip: echo is marginally faster compared to print
as echo does not return any value.
<?php
echo "<h2>PHP is fun!</h2>";
echo "Hello world!<br>";
echo "This", " string", " was", " made", " with multiple
parameters.";
?>
PHP Arrays
 An array stores multiple values in one single
variable:
Example
<?php
$cars = array("Volvo","BMW","Toyota");
echo "I like " . $cars[0] . ", " . $cars[1] . " and " .
$cars[2] . ".";
?>
Create an Array in PHP
• In PHP, the array() function is used to create an
array:
• Example :
$cars = array("Volvo","BMW","Toyota");
• In PHP, there are three types of arrays:
 Indexed arrays - Arrays with numeric index
 Associative arrays - Arrays with named keys
 Multidimensional arrays - Arrays containing one or more
arrays
PHP Indexed Arrays
 There are two ways to create indexed arrays:
 The index can be assigned automatically (index
always starts at 0):
 $cars=array("Volvo","BMW","Toyota");
OR
 The index can be assigned manually:
$cars[0]="Volvo";
$cars[1]="BMW";
$cars[2]="Toyota";
PHP Associative Arrays
 Associative arrays are arrays that use named keys
that you assign to them.
 There are two ways to create an associative array:
 $age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43
");
OR
 $age['Peter']="35";
$age['Ben']="37";
$age['Joe']="43";
PHP Associative Arrays
 Example
<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
echo "Peter is " . $age['Peter'] . " years old.";
?>
// Output : Peter is 35 years old.
PHP Multidimensional Arrays
 An array can also contain another array as a value,
which in turn can hold other arrays as well. In such a
way we can create two- or three-dimensional arrays:
Example
<?php
// A two-dimensional array:
$cars = array
(
array("Volvo",100,96),
array("BMW",60,59),
array("Toyota",110,100)
);
?>
The foreach Loop
• The foreach loop works only on arrays, and is used to
loop through each key/value pair in an array.
foreach ($array as $value)
{
code to be executed;
}
For every loop iteration, the value of the
current array element is assigned to
$value (and the array pointer is moved by
one) - so on the next loop iteration, you'll
be looking at the next array value.
The foreach Loop
Example:
<?php
$x=array("one","two","three");
foreach ($x as $value)
{
echo $value . "<br>";
}
?>
PHP Functions
 PHP User Defined Functions
 Besides the built-in PHP functions, we can create our own
functions.
 A function is a block of statements that can be used repeatedly in a
program.
 A function will not execute immediately when a page loads.
 A function will be executed by a call to the function.
 Create a User Defined Function in PHP
 A user defined function declaration starts with the word "function":
Syntax
function functionName(arg1, arg2…)
{
code to be executed;
}
 Note: A function name can start with a letter or underscore (not a
number).
GET Vs POST
PHP $_GET Variable
• The predefined $_GET variable is used to collect
values in a form with method="get"
• Information sent from a form with the GET method is
visible to everyone (it will be displayed in the
browser's address bar) and has limits on the amount
of information to send.
• Example
<form action="welcome.php" method="get">
Name: <input type="text" name="fname">
Age: <input type="text" name="age">
<input type="submit">
</form>
• When the user clicks the "Submit" button, the URL sent
to the server could look something like this:
http://www.w3schools.com/welcome.php?fname=Peter&age=37
• The "welcome.php" file can now use the $_GET variable
to collect form data as follow:
Welcome <?php echo $_GET["fname"]; ?>.<br>
You are <?php echo $_GET["age"]; ?> years old!
The $_POST Variable
• The predefined $_POST variable is used to collect
values from a form sent with method="post".
• Information sent from a form with the POST method
is invisible to others and has no limits on the amount
of information to send.
• Note: However, there is an 8 MB max size for the
POST method, by default (can be changed by
setting the post_max_size in the php.ini file).

More Related Content

What's hot

Web Development using HTML & CSS
Web Development using HTML & CSSWeb Development using HTML & CSS
Web Development using HTML & CSS
Brainware Consultancy Pvt Ltd
 
HTML Forms
HTML FormsHTML Forms
HTML Forms
Ravinder Kamboj
 
Html frames
Html framesHtml frames
Html frames
eShikshak
 
Php string function
Php string function Php string function
Php string function
Ravi Bhadauria
 
Span and Div tags in HTML
Span and Div tags in HTMLSpan and Div tags in HTML
Span and Div tags in HTML
Biswadip Goswami
 
Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS Presentation
Shawn Calvert
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
Tiji Thomas
 
Introduction to Html5
Introduction to Html5Introduction to Html5
Introduction to Html5
www.netgains.org
 
Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/js
Knoldus Inc.
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
Arulmurugan Rajaraman
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
Gil Fink
 
jQuery
jQueryjQuery
HTML CSS Basics
HTML CSS BasicsHTML CSS Basics
HTML CSS Basics
Mai Moustafa
 

What's hot (20)

Js ppt
Js pptJs ppt
Js ppt
 
Web Development using HTML & CSS
Web Development using HTML & CSSWeb Development using HTML & CSS
Web Development using HTML & CSS
 
HTML Forms
HTML FormsHTML Forms
HTML Forms
 
Html frames
Html framesHtml frames
Html frames
 
Php string function
Php string function Php string function
Php string function
 
Span and Div tags in HTML
Span and Div tags in HTMLSpan and Div tags in HTML
Span and Div tags in HTML
 
Html presentation
Html presentationHtml presentation
Html presentation
 
Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS Presentation
 
Html Ppt
Html PptHtml Ppt
Html Ppt
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
 
Introduction to Html5
Introduction to Html5Introduction to Html5
Introduction to Html5
 
Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/js
 
php
phpphp
php
 
CSS
CSSCSS
CSS
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Css Ppt
Css PptCss Ppt
Css Ppt
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
 
jQuery
jQueryjQuery
jQuery
 
HTML CSS Basics
HTML CSS BasicsHTML CSS Basics
HTML CSS Basics
 
Dom
DomDom
Dom
 

Similar to Introduction to php

Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
wahidullah mudaser
 
Php
PhpPhp
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
Arti Parab Academics
 
Php by shivitomer
Php by shivitomerPhp by shivitomer
Php by shivitomer
Shivi Tomer
 
PHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERSPHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERS
Aminiel Michael
 
PHP
PHPPHP
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
 
Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
Nisa Soomro
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
HambardeAtharva
 
1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_masterjeeva indra
 
Lecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdfLecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdf
ShaimaaMohamedGalal
 
Php tutorial from_beginner_to_master
Php tutorial from_beginner_to_masterPhp tutorial from_beginner_to_master
Php tutorial from_beginner_to_masterPrinceGuru MS
 
Basic php 5
Basic php 5Basic php 5
Basic php 5
Engr. Raud Ahmed
 
Day1
Day1Day1
Day1
IRWAA LLC
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting language
Elmer Concepcion Jr.
 
Materi Dasar PHP
Materi Dasar PHPMateri Dasar PHP
Materi Dasar PHP
Robby Firmansyah
 
Introduction to PHP.ppt
Introduction to PHP.pptIntroduction to PHP.ppt
Introduction to PHP.ppt
SanthiNivas
 

Similar to Introduction to php (20)

Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
Php
PhpPhp
Php
 
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
 
Php by shivitomer
Php by shivitomerPhp by shivitomer
Php by shivitomer
 
PHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERSPHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERS
 
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)
 
Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
 
Php Basics
Php BasicsPhp Basics
Php Basics
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
 
1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master
 
Lecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdfLecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdf
 
Php tutorial from_beginner_to_master
Php tutorial from_beginner_to_masterPhp tutorial from_beginner_to_master
Php tutorial from_beginner_to_master
 
Basic php 5
Basic php 5Basic php 5
Basic php 5
 
Day1
Day1Day1
Day1
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting language
 
Materi Dasar PHP
Materi Dasar PHPMateri Dasar PHP
Materi Dasar PHP
 
Introduction to PHP.ppt
Introduction to PHP.pptIntroduction to PHP.ppt
Introduction to PHP.ppt
 

More from Taha Malampatti

Lex & yacc
Lex & yaccLex & yacc
Lex & yacc
Taha Malampatti
 
Cultural heritage tourism
Cultural heritage tourismCultural heritage tourism
Cultural heritage tourism
Taha Malampatti
 
Request dispacther interface ppt
Request dispacther interface pptRequest dispacther interface ppt
Request dispacther interface ppt
Taha Malampatti
 
Introduction to Android ppt
Introduction to Android pptIntroduction to Android ppt
Introduction to Android ppt
Taha Malampatti
 
Intodcution to Html
Intodcution to HtmlIntodcution to Html
Intodcution to Html
Taha Malampatti
 
Database Connectivity in PHP
Database Connectivity in PHPDatabase Connectivity in PHP
Database Connectivity in PHP
Taha Malampatti
 
Cox and Kings Pvt Industrial Training
Cox and Kings Pvt Industrial TrainingCox and Kings Pvt Industrial Training
Cox and Kings Pvt Industrial Training
Taha Malampatti
 
Steganography ppt
Steganography pptSteganography ppt
Steganography ppt
Taha Malampatti
 
An application of 8085 register interfacing with LCD
An application  of 8085 register interfacing with LCDAn application  of 8085 register interfacing with LCD
An application of 8085 register interfacing with LCD
Taha Malampatti
 
An application of 8085 register interfacing with LED
An application  of 8085 register interfacing with LEDAn application  of 8085 register interfacing with LED
An application of 8085 register interfacing with LED
Taha Malampatti
 
Java Virtual Machine
Java Virtual MachineJava Virtual Machine
Java Virtual Machine
Taha Malampatti
 
The sunsparc architecture
The sunsparc architectureThe sunsparc architecture
The sunsparc architecture
Taha Malampatti
 
Orthogonal Projection
Orthogonal ProjectionOrthogonal Projection
Orthogonal Projection
Taha Malampatti
 
Apple inc
Apple incApple inc
Apple inc
Taha Malampatti
 
Blood donation
Blood donationBlood donation
Blood donation
Taha Malampatti
 
Compressors and its applications
Compressors and its applicationsCompressors and its applications
Compressors and its applications
Taha Malampatti
 
Laws Of Gravitation
Laws Of GravitationLaws Of Gravitation
Laws Of Gravitation
Taha Malampatti
 

More from Taha Malampatti (17)

Lex & yacc
Lex & yaccLex & yacc
Lex & yacc
 
Cultural heritage tourism
Cultural heritage tourismCultural heritage tourism
Cultural heritage tourism
 
Request dispacther interface ppt
Request dispacther interface pptRequest dispacther interface ppt
Request dispacther interface ppt
 
Introduction to Android ppt
Introduction to Android pptIntroduction to Android ppt
Introduction to Android ppt
 
Intodcution to Html
Intodcution to HtmlIntodcution to Html
Intodcution to Html
 
Database Connectivity in PHP
Database Connectivity in PHPDatabase Connectivity in PHP
Database Connectivity in PHP
 
Cox and Kings Pvt Industrial Training
Cox and Kings Pvt Industrial TrainingCox and Kings Pvt Industrial Training
Cox and Kings Pvt Industrial Training
 
Steganography ppt
Steganography pptSteganography ppt
Steganography ppt
 
An application of 8085 register interfacing with LCD
An application  of 8085 register interfacing with LCDAn application  of 8085 register interfacing with LCD
An application of 8085 register interfacing with LCD
 
An application of 8085 register interfacing with LED
An application  of 8085 register interfacing with LEDAn application  of 8085 register interfacing with LED
An application of 8085 register interfacing with LED
 
Java Virtual Machine
Java Virtual MachineJava Virtual Machine
Java Virtual Machine
 
The sunsparc architecture
The sunsparc architectureThe sunsparc architecture
The sunsparc architecture
 
Orthogonal Projection
Orthogonal ProjectionOrthogonal Projection
Orthogonal Projection
 
Apple inc
Apple incApple inc
Apple inc
 
Blood donation
Blood donationBlood donation
Blood donation
 
Compressors and its applications
Compressors and its applicationsCompressors and its applications
Compressors and its applications
 
Laws Of Gravitation
Laws Of GravitationLaws Of Gravitation
Laws Of Gravitation
 

Recently uploaded

power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
Kamal Acharya
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
ShahidSultan24
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
ssuser9bd3ba
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 

Recently uploaded (20)

power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 

Introduction to php

  • 1. PHP : Hypertext Preprocessor
  • 2. What is PHP?  PHP stands for PHP: Hypertext Preprocessor  PHP is a widely-used, open source scripting language  PHP scripts are executed on the server  PHP is free to download and use
  • 3. What is a PHP File?  PHP files can contain text, HTML, JavaScript code, and PHP code  PHP code are executed on the server, and the result is returned to the browser as plain HTML  PHP files have a default file extension of ".php"
  • 4. What Can PHP Do?  PHP can generate dynamic page content  PHP can create, open, read, write, and close files on the server  PHP can collect form data  PHP can send and receive cookies  PHP can add, delete, modify data in your database  PHP can restrict users to access some pages on your website  PHP can encrypt data
  • 5. Why PHP?  PHP runs on different platforms (Windows, Linux, Unix, Mac OS X, etc.)  PHP is compatible with almost all servers used today (Apache, IIS, etc.)  PHP has support for a wide range of databases  PHP is free. Download it from the official PHP resource: www.php.net  PHP is easy to learn and runs efficiently on the server side
  • 6. Set Up PHP on Your Own PC  However, if your server does not support PHP, you must:  install a web server  install PHP  install a database, such as MySQL  The official PHP website (PHP.net) has installation instructions for PHP: http://php.net/manual/en/install.php
  • 7. Basic PHP Syntax 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".
  • 8. Comments in PHP  Example <html> <body> <?php //This is a PHP comment line /* This is a PHP comment block */ ?> </body> </html>
  • 9. PHP Variables  Variable can have short names (like x and y) or more descriptive names (age, carname, totalvolume).  Rules for PHP variables:  A variable starts with the $ sign, followed by the name of the variable  A variable name must begin with a letter or the underscore character  A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )  A variable name should not contain spaces  Variable names are case sensitive ($y and $Y are two different variables)
  • 10. Creating (Declaring) PHP Variables  PHP has no command for declaring a variable.  A variable is created the moment you first assign a value to it:  $txt="Hello world!"; $x=5;  After the execution of the statements above, the variable txt will hold the value Hello world!, and the variable xwill hold the value 5.  Note: When you assign a text value to a variable, put quotes around the value.
  • 11. PHP is a Loosely Typed Language  In the example above, notice that we did not have to tell PHP which data type the variable is.  PHP automatically converts the variable to the correct data type, depending on its value.  In a strongly typed programming language, we will have to declare (define) the type and name of the variable before using it.
  • 12. PHP Variable Scopes  The scope of a variable is the part of the script where the variable can be referenced/used.  PHP has four different variable scopes:  local  global  static  parameter
  • 13. Local Scope  A variable declared within a PHP function is local and can only be accessed within that function:  Example <?php $x=5; // global scope function myTest() { echo $x; // local scope } myTest(); ?>
  • 14. Global Scope  A variable that is defined outside of any function, has a global scope.  Global variables can be accessed from any part of the script, EXCEPT from within a function.  To access a global variable from within a function, use the global keyword:
  • 15. Global Scope  Example  <?php $x=5; // global scope $y=10; // global scope function myTest() { global $x,$y; $y=$x+$y; } myTest(); echo $y; // outputs 15 ?>
  • 16. Static Scope  When a function is completed, all of its variables are normally deleted. However, sometimes you want a local variable to not be deleted.  To do this, use the static keyword when you first declare the variable:
  • 17. Static Scope  Example <?php function myTest() { static $x=0; echo $x; $x++; } myTest(); myTest(); myTest(); ?>  OUTPUT ?
  • 18. Parameter Scope  A parameter is a local variable whose value is passed to the function by the calling code.  Parameters are declared in a parameter list as part of the function declaration:  Example : <?php function myTest($x) { echo $x; } myTest(5); ?>
  • 19. PHP echo and print Statements  In PHP there is two basic ways to get output: echo and print.  There are some differences between echo and print:  echo - can output one or more strings  print - can only output one string, and returns always 1  Tip: echo is marginally faster compared to print as echo does not return any value. <?php echo "<h2>PHP is fun!</h2>"; echo "Hello world!<br>"; echo "This", " string", " was", " made", " with multiple parameters."; ?>
  • 20. PHP Arrays  An array stores multiple values in one single variable: Example <?php $cars = array("Volvo","BMW","Toyota"); echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . "."; ?>
  • 21. Create an Array in PHP • In PHP, the array() function is used to create an array: • Example : $cars = array("Volvo","BMW","Toyota"); • In PHP, there are three types of arrays:  Indexed arrays - Arrays with numeric index  Associative arrays - Arrays with named keys  Multidimensional arrays - Arrays containing one or more arrays
  • 22. PHP Indexed Arrays  There are two ways to create indexed arrays:  The index can be assigned automatically (index always starts at 0):  $cars=array("Volvo","BMW","Toyota"); OR  The index can be assigned manually: $cars[0]="Volvo"; $cars[1]="BMW"; $cars[2]="Toyota";
  • 23. PHP Associative Arrays  Associative arrays are arrays that use named keys that you assign to them.  There are two ways to create an associative array:  $age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43 "); OR  $age['Peter']="35"; $age['Ben']="37"; $age['Joe']="43";
  • 24. PHP Associative Arrays  Example <?php $age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43"); echo "Peter is " . $age['Peter'] . " years old."; ?> // Output : Peter is 35 years old.
  • 25. PHP Multidimensional Arrays  An array can also contain another array as a value, which in turn can hold other arrays as well. In such a way we can create two- or three-dimensional arrays: Example <?php // A two-dimensional array: $cars = array ( array("Volvo",100,96), array("BMW",60,59), array("Toyota",110,100) ); ?>
  • 26. The foreach Loop • The foreach loop works only on arrays, and is used to loop through each key/value pair in an array. foreach ($array as $value) { code to be executed; } For every loop iteration, the value of the current array element is assigned to $value (and the array pointer is moved by one) - so on the next loop iteration, you'll be looking at the next array value.
  • 27. The foreach Loop Example: <?php $x=array("one","two","three"); foreach ($x as $value) { echo $value . "<br>"; } ?>
  • 28. PHP Functions  PHP User Defined Functions  Besides the built-in PHP functions, we can create our own functions.  A function is a block of statements that can be used repeatedly in a program.  A function will not execute immediately when a page loads.  A function will be executed by a call to the function.  Create a User Defined Function in PHP  A user defined function declaration starts with the word "function": Syntax function functionName(arg1, arg2…) { code to be executed; }  Note: A function name can start with a letter or underscore (not a number).
  • 30. PHP $_GET Variable • The predefined $_GET variable is used to collect values in a form with method="get" • Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send. • Example <form action="welcome.php" method="get"> Name: <input type="text" name="fname"> Age: <input type="text" name="age"> <input type="submit"> </form>
  • 31. • When the user clicks the "Submit" button, the URL sent to the server could look something like this: http://www.w3schools.com/welcome.php?fname=Peter&age=37 • The "welcome.php" file can now use the $_GET variable to collect form data as follow: Welcome <?php echo $_GET["fname"]; ?>.<br> You are <?php echo $_GET["age"]; ?> years old!
  • 32. The $_POST Variable • The predefined $_POST variable is used to collect values from a form sent with method="post". • Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send. • Note: However, there is an 8 MB max size for the POST method, by default (can be changed by setting the post_max_size in the php.ini file).