2. 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?
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:
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
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
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