SlideShare a Scribd company logo
Getting Started
with PHP
MemphisPHP.org
Joe Ferguson - joe@joeferguson.me
Professionally
● Web Developer at RocketFuel
● PHP / LAMP Focused
Semi Professional
● Co-Organizer for MemphisPHP.org
● MidsouthMakers - Hackerspace Leader
● HACKmemphis.com Organizer
Who is this guy?
It’s a recursive anagram…
PHP: Hypertext Preprocessor is a widely used, general-
purpose scripting language that was originally designed
for web development to produce dynamic web pages
What is PHP?
● Widespread Availability
○ PHP is now installed on more than 244 million
websites and 2.1 million web servers (Source:
Wikipedia)
● Ease of use.
○ Extremely simple for newcomers
○ Advanced features for professional programmers
○ Looslely typed
● Great Community Support
● Many corporations throwing support
behind PHP projects
Why use PHP?
Who uses it? What runs on PHP?
...and many, MANY others
<html>
<head>
<title>Example 1 - Getting Started with
PHP<</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
Jumping into PHP - Example 1
You can add any content to a PHP file.
Anything not between PHP tags is ignored by
PHP.
Using echo, you can print from PHP. As
example 1 shows, even PHP.
Example 1 - Basic HTML + PHP
PHP is very easy to pick up and run with.
This is one of the main reasons it is so
widespread.
Looks easy right?
$_GET Variables come from the URL
Bad:
<?php
$name = $_GET['name'];
?>
NEVER trust data from your users!
Good:
<?php
if(isset($_GET['name'])){
$name = filter_var($_GET['name'],FILTER_SANITIZE_STRING);
}
?>
Getting Data from the User
So what is happening?
● First we check if the name exists by
looking at $_GET[‘name’]
○ if(isset($_GET['name'])){
● If it does exist, we pass it to a function to
sanitize the input and set the results equal
to $name
○ $name = filter_var($_GET['name'],FILTER_SANITIZE_STRING);
Getting Data from the User
● isset
● empty
● filter_var
● arrays
● strings
● omgwtf!
The best PHP resources:
● phptherightway.com
● php.net
I can’t keep track of all this!
PHP Specification Request (PSR)
The Framework Interop Group:
● PSR-0
● PSR-1
● PSR-2
Other Styles:
● PEAR Coding Standards
● Zend Coding Standards
OMG your { are on the wrong line!
There are subtle differences among the PSR
coding styles approved by the FIG.
If you’re wanting to maximize your
reusability: pick a PSR similar to the code
you are working with.
Most projects won’t take code if it doesn’t
match the style they have adopted.
Why so many? What do I use?
Strings
● echo ‘PHP is my favorite language’;
● $variable = ‘PHP is amazing’;
● echo "PHP! you'll be astonished";
● echo 'PHP! you'll be astonished';
Concatenation
● echo "Hello, " . $prefix . " " . $name;
Single quote strings do not get parsed.
Double quote strings get parsed. Are slower
than single quote strings because of this.
Before we get too complicated:
Simple Arrays:
<?php
$fruit = array();
$fruit[] = 'apple';
$fruit[] = 'pear';
$fruit[] = 'orange';
$fruit[] = 'lemon';
$fruit[] = 'pineapple';
?>
Arrays - associating values to keys
$food = array();
$food['fruit'] = array();
$food['fruit'][] = 'apple';
$food['fruit'][] = 'pear';
$food['fruit'][] = 'orange';
$food['fruit'][] = 'lemon';
$food['fruit'][] = 'pineapple';
$food['meat'] = array();
$food['meat'][] = 'bacon';
$food['meat'][] = 'steak';
$food['meat'][] = 'chicken';
$food['meat'][] = 'fish';
Multidimensional Arrays - Ex 5
● We know that PHP is awesome
● We know A LOT of people use PHP
● We’ve greeted the world of PHP
● We have seen how to get data from users
● We are absolute EXPERTS at Arrays
The Story So Far
Conditions
$name = 'Joe';
//$name = 'Bill the pony';
if($name == 'Joe'){
echo '<p>Hello Joe, welcome back</p>';
} else {
echo '<p>Hello ' . $name . '</p>';
}
Putting it together… Example 6
Foreach steps through each item.
You perform some action on each item.
foreach($fruit AS $key => $value){
echo '<li>' . $value . '</p>';
}
For Loops - Example 7
While loops perform the action while a
condition is met and then stops.
$fruit_count = count($fruit);
$f = 0;
while ($f < $fruit_count){
echo '<li>' . $fruit[$f] . '</li>';
$f++;
}
While Loops - Example 8
function getFruit(){
$fruit = array();
$fruit[] = 'apple';
$fruit[] = 'pear';
$fruit[] = 'orange';
$fruit[] = 'lemon';
$fruit[] = 'pineapple';
return $fruit;
}
FUNctions - Example 9
Using the previous getFruit function:
$fruit = getFruit();
$fruit is now an array created by the function
Using Functions - Example 9
● You can pass data into an array by adding
arguments
function getFruitOrMeat($fruit_or_meat){
…
}
$fruit_or_meat is data we are passing into
the getFruitOrMeat function
Function Arguments Example 10
The best PHP resources:
● phptherightway.com
● php.net
Online Learning:
● codecademy.com
● php.net/manual/en/getting-started.php
More Information

More Related Content

What's hot (20)

PDF
PHP an intro -1
Kanchilug
 
ODT
Huong dan cai dat hadoop
Quỳnh Phan
 
PDF
Path::Tiny
waniji
 
PPTX
Phphacku iitd
Sorabh Jain
 
PPTX
Hardcore PHP
Roberto Luis Bisbé
 
PPTX
Php hacku
Tom Praison Praison
 
PPT
Php mysql
Manish Jain
 
PDF
PuppetCamp SEA @ Blk 71 - Nagios in under 10 mins with Puppet
OlinData
 
PDF
PuppetCamp SEA @ Blk 71 - Nagios in under 10 mins with Puppet
Walter Heck
 
PPTX
Hands on django part 1
MicroPyramid .
 
PDF
Php tutorial handout
SBalan Balan
 
PDF
お題でGroovyプログラミング: Part A
Kazuchika Sekiya
 
ODP
HTML Templates Using Clear Silver
PaulWay
 
PPTX
Php 7 hhvm and co
Pierre Joye
 
TXT
Fcontratos
karlloss
 
PDF
Client-side Storage 
T W
 
PDF
Clean Code Tips (Day 1 )
Ahmed Abd El Ftah
 
PDF
Not Really PHP by the book
Ryan Kilfedder
 
ODP
Perl5i
Marcos Rebelo
 
PPT
Php, mysq lpart1
Subhasis Nayak
 
PHP an intro -1
Kanchilug
 
Huong dan cai dat hadoop
Quỳnh Phan
 
Path::Tiny
waniji
 
Phphacku iitd
Sorabh Jain
 
Hardcore PHP
Roberto Luis Bisbé
 
Php mysql
Manish Jain
 
PuppetCamp SEA @ Blk 71 - Nagios in under 10 mins with Puppet
OlinData
 
PuppetCamp SEA @ Blk 71 - Nagios in under 10 mins with Puppet
Walter Heck
 
Hands on django part 1
MicroPyramid .
 
Php tutorial handout
SBalan Balan
 
お題でGroovyプログラミング: Part A
Kazuchika Sekiya
 
HTML Templates Using Clear Silver
PaulWay
 
Php 7 hhvm and co
Pierre Joye
 
Fcontratos
karlloss
 
Client-side Storage 
T W
 
Clean Code Tips (Day 1 )
Ahmed Abd El Ftah
 
Not Really PHP by the book
Ryan Kilfedder
 
Php, mysq lpart1
Subhasis Nayak
 

Similar to Getting started with php (20)

PPTX
Day1
IRWAA LLC
 
PPT
Php(report)
Yhannah
 
PPT
PHP - Introduction to PHP Fundamentals
Vibrant Technologies & Computers
 
PPT
Php classes in mumbai
Vibrant Technologies & Computers
 
PPTX
php.pptx
nusky ahamed
 
PPTX
Lecture 6: Introduction to PHP and Mysql .pptx
AOmaAli
 
PPT
PHP and MySQL with snapshots
richambra
 
PPT
Synapseindia reviews on array php
saritasingh19866
 
PPT
PHP - Introduction to PHP
Vibrant Technologies & Computers
 
PPT
PHP MySQL Workshop - facehook
Shashank Skills Academy
 
PPT
PHP - Introduction to PHP - Mazenet Solution
Mazenetsolution
 
PPT
Prersentation
Ashwin Deora
 
PPT
php41.ppt
Nishant804733
 
PPT
PHP InterLevel.ppt
NBACriteria2SICET
 
PPT
php-I-slides.ppt
SsewankamboErma
 
PPTX
Unit 4-6 sem 7 Web Technologies.pptx
prathameshp9922
 
PPTX
unit 1.pptx
adityathote3
 
PPT
Intro to PHP
Sandy Smith
 
PPTX
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
DRambabu3
 
PPT
05php
anshkhurana01
 
Day1
IRWAA LLC
 
Php(report)
Yhannah
 
PHP - Introduction to PHP Fundamentals
Vibrant Technologies & Computers
 
Php classes in mumbai
Vibrant Technologies & Computers
 
php.pptx
nusky ahamed
 
Lecture 6: Introduction to PHP and Mysql .pptx
AOmaAli
 
PHP and MySQL with snapshots
richambra
 
Synapseindia reviews on array php
saritasingh19866
 
PHP - Introduction to PHP
Vibrant Technologies & Computers
 
PHP MySQL Workshop - facehook
Shashank Skills Academy
 
PHP - Introduction to PHP - Mazenet Solution
Mazenetsolution
 
Prersentation
Ashwin Deora
 
php41.ppt
Nishant804733
 
PHP InterLevel.ppt
NBACriteria2SICET
 
php-I-slides.ppt
SsewankamboErma
 
Unit 4-6 sem 7 Web Technologies.pptx
prathameshp9922
 
unit 1.pptx
adityathote3
 
Intro to PHP
Sandy Smith
 
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
DRambabu3
 
Ad

More from Joe Ferguson (20)

PDF
Modern infrastructure as code with ansible cake fest 2021
Joe Ferguson
 
PDF
Modern infrastructure as code with ansible PyTN
Joe Ferguson
 
PDF
Slim PHP when you don't need the kitchen sink
Joe Ferguson
 
PDF
Throwing Laravel into your Legacy App™
Joe Ferguson
 
PDF
DevSpace Conf 2017 - Making sense of the provisioning circus
Joe Ferguson
 
PDF
Release and-dependency-management memphis python
Joe Ferguson
 
PDF
Composer at Scale, Release and Dependency Management
Joe Ferguson
 
PDF
Put an end to regression with codeception testing
Joe Ferguson
 
PDF
Midwest PHP 2017 DevOps For Small team
Joe Ferguson
 
PDF
All the Laravel Things – Up & Running to Making $$
Joe Ferguson
 
PDF
Console Apps: php artisan forthe:win
Joe Ferguson
 
PDF
Console Apps: php artisan forthe:win
Joe Ferguson
 
PDF
All the Laravel things: up and running to making $$
Joe Ferguson
 
PDF
So You Just Inherited a $Legacy Application… NomadPHP July 2016
Joe Ferguson
 
PDF
So You Just Inherited a $Legacy Application...
Joe Ferguson
 
PDF
Laravel Forge: Hello World to Hello Production
Joe Ferguson
 
PDF
MidwestPHP 2016 - Adventures in Laravel 5
Joe Ferguson
 
PDF
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Joe Ferguson
 
PDF
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
Joe Ferguson
 
PDF
php[world] 2015 Laravel 5.1: From Homestead to the Cloud
Joe Ferguson
 
Modern infrastructure as code with ansible cake fest 2021
Joe Ferguson
 
Modern infrastructure as code with ansible PyTN
Joe Ferguson
 
Slim PHP when you don't need the kitchen sink
Joe Ferguson
 
Throwing Laravel into your Legacy App™
Joe Ferguson
 
DevSpace Conf 2017 - Making sense of the provisioning circus
Joe Ferguson
 
Release and-dependency-management memphis python
Joe Ferguson
 
Composer at Scale, Release and Dependency Management
Joe Ferguson
 
Put an end to regression with codeception testing
Joe Ferguson
 
Midwest PHP 2017 DevOps For Small team
Joe Ferguson
 
All the Laravel Things – Up & Running to Making $$
Joe Ferguson
 
Console Apps: php artisan forthe:win
Joe Ferguson
 
Console Apps: php artisan forthe:win
Joe Ferguson
 
All the Laravel things: up and running to making $$
Joe Ferguson
 
So You Just Inherited a $Legacy Application… NomadPHP July 2016
Joe Ferguson
 
So You Just Inherited a $Legacy Application...
Joe Ferguson
 
Laravel Forge: Hello World to Hello Production
Joe Ferguson
 
MidwestPHP 2016 - Adventures in Laravel 5
Joe Ferguson
 
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Joe Ferguson
 
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
Joe Ferguson
 
php[world] 2015 Laravel 5.1: From Homestead to the Cloud
Joe Ferguson
 
Ad

Recently uploaded (20)

PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Digital Circuits, important subject in CS
contactparinay1
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 

Getting started with php

  • 2. Joe Ferguson - [email protected] Professionally ● Web Developer at RocketFuel ● PHP / LAMP Focused Semi Professional ● Co-Organizer for MemphisPHP.org ● MidsouthMakers - Hackerspace Leader ● HACKmemphis.com Organizer Who is this guy?
  • 3. It’s a recursive anagram… PHP: Hypertext Preprocessor is a widely used, general- purpose scripting language that was originally designed for web development to produce dynamic web pages What is PHP?
  • 4. ● Widespread Availability ○ PHP is now installed on more than 244 million websites and 2.1 million web servers (Source: Wikipedia) ● Ease of use. ○ Extremely simple for newcomers ○ Advanced features for professional programmers ○ Looslely typed ● Great Community Support ● Many corporations throwing support behind PHP projects Why use PHP?
  • 5. Who uses it? What runs on PHP? ...and many, MANY others
  • 6. <html> <head> <title>Example 1 - Getting Started with PHP<</title> </head> <body> <?php echo '<p>Hello World</p>'; ?> </body> </html> Jumping into PHP - Example 1
  • 7. You can add any content to a PHP file. Anything not between PHP tags is ignored by PHP. Using echo, you can print from PHP. As example 1 shows, even PHP. Example 1 - Basic HTML + PHP
  • 8. PHP is very easy to pick up and run with. This is one of the main reasons it is so widespread. Looks easy right?
  • 9. $_GET Variables come from the URL Bad: <?php $name = $_GET['name']; ?> NEVER trust data from your users! Good: <?php if(isset($_GET['name'])){ $name = filter_var($_GET['name'],FILTER_SANITIZE_STRING); } ?> Getting Data from the User
  • 10. So what is happening? ● First we check if the name exists by looking at $_GET[‘name’] ○ if(isset($_GET['name'])){ ● If it does exist, we pass it to a function to sanitize the input and set the results equal to $name ○ $name = filter_var($_GET['name'],FILTER_SANITIZE_STRING); Getting Data from the User
  • 11. ● isset ● empty ● filter_var ● arrays ● strings ● omgwtf! The best PHP resources: ● phptherightway.com ● php.net I can’t keep track of all this!
  • 12. PHP Specification Request (PSR) The Framework Interop Group: ● PSR-0 ● PSR-1 ● PSR-2 Other Styles: ● PEAR Coding Standards ● Zend Coding Standards OMG your { are on the wrong line!
  • 13. There are subtle differences among the PSR coding styles approved by the FIG. If you’re wanting to maximize your reusability: pick a PSR similar to the code you are working with. Most projects won’t take code if it doesn’t match the style they have adopted. Why so many? What do I use?
  • 14. Strings ● echo ‘PHP is my favorite language’; ● $variable = ‘PHP is amazing’; ● echo "PHP! you'll be astonished"; ● echo 'PHP! you'll be astonished'; Concatenation ● echo "Hello, " . $prefix . " " . $name; Single quote strings do not get parsed. Double quote strings get parsed. Are slower than single quote strings because of this. Before we get too complicated:
  • 15. Simple Arrays: <?php $fruit = array(); $fruit[] = 'apple'; $fruit[] = 'pear'; $fruit[] = 'orange'; $fruit[] = 'lemon'; $fruit[] = 'pineapple'; ?> Arrays - associating values to keys
  • 16. $food = array(); $food['fruit'] = array(); $food['fruit'][] = 'apple'; $food['fruit'][] = 'pear'; $food['fruit'][] = 'orange'; $food['fruit'][] = 'lemon'; $food['fruit'][] = 'pineapple'; $food['meat'] = array(); $food['meat'][] = 'bacon'; $food['meat'][] = 'steak'; $food['meat'][] = 'chicken'; $food['meat'][] = 'fish'; Multidimensional Arrays - Ex 5
  • 17. ● We know that PHP is awesome ● We know A LOT of people use PHP ● We’ve greeted the world of PHP ● We have seen how to get data from users ● We are absolute EXPERTS at Arrays The Story So Far
  • 18. Conditions $name = 'Joe'; //$name = 'Bill the pony'; if($name == 'Joe'){ echo '<p>Hello Joe, welcome back</p>'; } else { echo '<p>Hello ' . $name . '</p>'; } Putting it together… Example 6
  • 19. Foreach steps through each item. You perform some action on each item. foreach($fruit AS $key => $value){ echo '<li>' . $value . '</p>'; } For Loops - Example 7
  • 20. While loops perform the action while a condition is met and then stops. $fruit_count = count($fruit); $f = 0; while ($f < $fruit_count){ echo '<li>' . $fruit[$f] . '</li>'; $f++; } While Loops - Example 8
  • 21. function getFruit(){ $fruit = array(); $fruit[] = 'apple'; $fruit[] = 'pear'; $fruit[] = 'orange'; $fruit[] = 'lemon'; $fruit[] = 'pineapple'; return $fruit; } FUNctions - Example 9
  • 22. Using the previous getFruit function: $fruit = getFruit(); $fruit is now an array created by the function Using Functions - Example 9
  • 23. ● You can pass data into an array by adding arguments function getFruitOrMeat($fruit_or_meat){ … } $fruit_or_meat is data we are passing into the getFruitOrMeat function Function Arguments Example 10
  • 24. The best PHP resources: ● phptherightway.com ● php.net Online Learning: ● codecademy.com ● php.net/manual/en/getting-started.php More Information