SlideShare ist ein Scribd-Unternehmen logo
1 von 33
Underground PHP
         
    by Rob Hawkes
   i7872333@bournemouth.ac.uk
The ground rules
What the sessions are
✽   Somewhere to admit lack of
    understanding
✽   Covering areas missed in workshops
✽   Helping you understand programming
    theory – critical!
✽   Focussing on the “why” over “how”
✽   A launch pad for further learning
And what they aren’t

✽   Quick fix for The Station
    •   Will provide examples of when to use techniques in
        context
    •   Will not provide code to copy & paste

✽   Easy
    •   PHP takes time & effort to learn
These go without saying

✽   Provide your own equipment
    •   We might not always be in the labs
    •   I can’t provide individual web space

✽   Don’t piss about
    •   Please only come if you genuinely want to learn
    •   I won’t waste my time or yours
VIVA LA RESISTANCE!
Session 1: The Basics
What we’ll cover


✽   An introduction to PHP
✽   Where to get help when you’re stuck
✽   Best practice when coding
✽   Fundamental knowledge
PHP: An introduction
What is PHP?
✽   Stands for PHP: Hypertext Preprocessor
    •   Yes, a recursive acronym. Funky!

✽   Run directly on the web server
    •   Windows, Linux, and Mac

✽   Makes web pages dynamic
    •   Calculations, database interaction, etc.

✽   Latest version is PHP 5
    •   Introduces features not supported in PHP 4
Basic PHP process

    User's Browser


    Web Server (Apache)




        PHP Engine




     MySQL Database
Where to get help
Online help
✽   Official PHP documentation
    •   php.net

✽   Stack Overflow
    •   stackoverflow.com

✽   SitePoint forums
    •   sitepoint.com/forums

✽   Google
Offline help

✽   Don’t look at me
    •   Would love to but I don’t have the time

✽   Books
    •   PHP and MySQL for Dynamic Web Sites
    •   PHP and MySQL Bible
Best practice
Indentation & spacing


✽   Neat & tidy
✽   Makes code readable
✽   Less prone to error
✽   Easier to debug in future
Indentation & spacing
Unindented                           Indented
<?php                                <?php
$array=array(‘1’,‘2’,‘3’,‘4’,‘5’);   $array = array(‘1’, ‘2’, ‘3’, ‘4’, ‘5’);
$count=count($array);                $count = count($array);
for($i=0;$i<$count;$i++){
if($i==2){                           for ($i = 0; $i < $count; $i++) {
echo $array[$i];                        if ($i == 2) {
}                                           echo $array[$i];
}                                       }
?>                                   }
                                     ?>
Unindented   Indented
Comment everything
✽   // comments a single line
✽   /* text */ comments multiple lines
✽   Helps with learning
✽   Make comments meaningful
    •   Explain in detail exactly what the code does

✽   Saves time when debugging
✽   Will save your arse many times
Naming conventions

✽   camelCase
    •   Always start with a lowercase letter
    •   Capitalise the first letter of any further words

✽   Meaningful names
    •   ShowProfile() rather than function1()
    •   Makes code readable at a glance
Further reading



✽   Zend Framework coding standards
    •   http://framework.zend.com/manual/en/coding-
        standard.html
Fundamental
 knowledge
General syntax

✽   Wrap all PHP within <?php and ?> tags
    •   Tells server that the code within is to be run through
        the PHP system

✽   End every line with a semicolon;
    •   Ok, not every line but enough to use that rule
    •   Lets the PHP system know where a line of code ends
    •   Most rookie errors are caused by forgetting semicolons
General syntax
✽   Use $variables to store data for later
    •   Variables are always preceded with a $ symbol
    •   They can’t begin with a number
    •   Any type of data can be stored inside a variable

✽   Echo and print
    •   Used to output data to the browser
    •   Negligible difference in performance between the two
    •   Most programmers use echo
Data types
Name             Short name      Notes
Boolean          bool            Truth value, either true or false

Integer          int             Whole number (eg. 5)

Floating point   float / double   Decimal fraction (eg. 1.7)

String           str             Series of characters, usually text,
                                 enclosed in quotation marks
Array            arr             Used to store multiple pieces of data
                                 in one place
Assignment operators
Operator   Example         Notes
=          $a = 1+4;       Assigns the left operand (variable) to
                           the value on the right

+=         $a += 5         Adds the value on the right the
                           existing value of $a

-=         $a -= 5         Subtracts the value on the right from
                           the existing value of $a

.=         $a .= ‘Hello’   Appends the value on the right to the
                           existing value of $a, mainly used with
                           strings
Arithmetic operators
Operator   Name             Notes
-$a        Negation         Opposite / reverse of $a

$a + $b    Addition         Sum of $a and $b

$a - $b    Subtraction      Difference of $a and $b

$a * $b    Multiplication   Product of $a and $b

$a / $b    Division         Quotient of $a and $b

$a % $b    Modulus          Remainder of $a divided by $b
Comparison operators
Operator    Name              Notes
$a == $b    Equal             True if $a is equal to $b
$a === $b   Identical         True if $a is equal to $b, and are of
                              the same data type
$a != $b    Not equal         True if $a is not equal to $b

$a !== $b   Not identical     True if $a is not equal to $b, or they
                              are not of the same data type
$a < $b     Less than         True if $a is less than $b

$a > $b     Greater than      True if $a is greater than $b

$a <= $b    Less than or      True if $a is less than or equal to $b
            equal to
$a >= $b    Greater than or   True if $a is greater than or equal to
            equal to          $b
Increment & decrement
Operator   Name             Notes
++$a       Pre-increment    Increase $a by one then return $a

$a++       Post-increment   Return $a then increase $a by one

--$a       Pre-decrement    Decrease $a by one then return $a

$a--       Post-decrement   Return $a then decrease $a by one
Logic operators
Operator     Name   Notes
$a and $b    And    True if both $a and $b are true

$a && $b     And    True if both $a and $b are true

$a or $b     Or     True if $a or $b is true

$a || $b     Or     True if $a or $b is true

$a xor $b    Xor    True if $a or $b is true, but not both

!$a          Not    True if $a is not true
Operator roundup

✽   PHP uses the same operators as most
    major programming languages
✽   = does not mean ‘equal to’
    •   = is used to assign a value
    •   == means ‘equal to’
Further reading
✽   PHP.net data types documentation
    •   http://www.php.net/manual/en/
        language.types.intro.php

✽   PHP.net operator documentation
    •   http://www.php.net/manual/en/
        language.operators.php

✽   PHP.net type comparison tables
    •   http://www.php.net/manual/en/
        types.comparisons.php
Any questions?

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to Perl - Day 2
Introduction to Perl - Day 2Introduction to Perl - Day 2
Introduction to Perl - Day 2
Dave Cross
 
4.7 Automate Loading Data with Little to No Duplicates!
4.7 Automate Loading Data with Little to No Duplicates!4.7 Automate Loading Data with Little to No Duplicates!
4.7 Automate Loading Data with Little to No Duplicates!
TargetX
 
Perl programming language
Perl programming languagePerl programming language
Perl programming language
Elie Obeid
 

Was ist angesagt? (20)

Perl Introduction
Perl IntroductionPerl Introduction
Perl Introduction
 
Basic PHP
Basic PHPBasic PHP
Basic PHP
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Learn PHP Basics
Learn PHP Basics Learn PHP Basics
Learn PHP Basics
 
Introduction to Perl - Day 2
Introduction to Perl - Day 2Introduction to Perl - Day 2
Introduction to Perl - Day 2
 
4.7 Automate Loading Data with Little to No Duplicates!
4.7 Automate Loading Data with Little to No Duplicates!4.7 Automate Loading Data with Little to No Duplicates!
4.7 Automate Loading Data with Little to No Duplicates!
 
PHP Basic
PHP BasicPHP Basic
PHP Basic
 
Perl tutorial
Perl tutorialPerl tutorial
Perl tutorial
 
Introduction to php php++
Introduction to php php++Introduction to php php++
Introduction to php php++
 
Dev traning 2016 basics of PHP
Dev traning 2016   basics of PHPDev traning 2016   basics of PHP
Dev traning 2016 basics of PHP
 
Perl programming language
Perl programming languagePerl programming language
Perl programming language
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 
Perl Basics with Examples
Perl Basics with ExamplesPerl Basics with Examples
Perl Basics with Examples
 
Introduction to Perl Best Practices
Introduction to Perl Best PracticesIntroduction to Perl Best Practices
Introduction to Perl Best Practices
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
 
05php
05php05php
05php
 
Beginning Perl
Beginning PerlBeginning Perl
Beginning Perl
 

Andere mochten auch

Learning Sessions #5 Pre Incubator - WindSync
Learning Sessions #5 Pre Incubator - WindSyncLearning Sessions #5 Pre Incubator - WindSync
Learning Sessions #5 Pre Incubator - WindSync
jvielman
 
Session2 pl online_course_26_may2011- final
Session2  pl online_course_26_may2011- finalSession2  pl online_course_26_may2011- final
Session2 pl online_course_26_may2011- final
LeslieOflahavan
 
Bb Security
Bb SecurityBb Security
Bb Security
justin92
 
Session4 pl online_course_30_september2011
Session4  pl online_course_30_september2011Session4  pl online_course_30_september2011
Session4 pl online_course_30_september2011
LeslieOflahavan
 
Boot to Gecko – The Web as a Platform
Boot to Gecko – The Web as a PlatformBoot to Gecko – The Web as a Platform
Boot to Gecko – The Web as a Platform
Robin Hawkes
 
2012.04.05 Learning Sessions #1: CityArtWorks + Mercury
2012.04.05 Learning Sessions #1: CityArtWorks + Mercury2012.04.05 Learning Sessions #1: CityArtWorks + Mercury
2012.04.05 Learning Sessions #1: CityArtWorks + Mercury
jvielman
 

Andere mochten auch (20)

Hw fdb(2)
Hw fdb(2)Hw fdb(2)
Hw fdb(2)
 
Learning Sessions #5 Pre Incubator - WindSync
Learning Sessions #5 Pre Incubator - WindSyncLearning Sessions #5 Pre Incubator - WindSync
Learning Sessions #5 Pre Incubator - WindSync
 
又一個誤聽 GAE 的悲劇
又一個誤聽 GAE 的悲劇又一個誤聽 GAE 的悲劇
又一個誤聽 GAE 的悲劇
 
MDN Hackday London - Boot to Gecko: The Future of Mobile
MDN Hackday London - Boot to Gecko: The Future of MobileMDN Hackday London - Boot to Gecko: The Future of Mobile
MDN Hackday London - Boot to Gecko: The Future of Mobile
 
Implikasi Pelaksanaan Undang Undang Desa (161115)
Implikasi Pelaksanaan Undang Undang Desa (161115)Implikasi Pelaksanaan Undang Undang Desa (161115)
Implikasi Pelaksanaan Undang Undang Desa (161115)
 
May 28 2010
May 28 2010May 28 2010
May 28 2010
 
Karz short presentation deck 12 2016
Karz short presentation deck 12 2016Karz short presentation deck 12 2016
Karz short presentation deck 12 2016
 
That's not what he said!
That's not what he said!That's not what he said!
That's not what he said!
 
Session2 pl online_course_26_may2011- final
Session2  pl online_course_26_may2011- finalSession2  pl online_course_26_may2011- final
Session2 pl online_course_26_may2011- final
 
090216 roma iucc_fbcei_dovwiner
090216 roma iucc_fbcei_dovwiner090216 roma iucc_fbcei_dovwiner
090216 roma iucc_fbcei_dovwiner
 
WebVisions – ViziCities: Bringing Cities to Life Using Big Data
WebVisions – ViziCities: Bringing Cities to Life Using Big DataWebVisions – ViziCities: Bringing Cities to Life Using Big Data
WebVisions – ViziCities: Bringing Cities to Life Using Big Data
 
HTML5 & JavaScript: The Future Now
HTML5 & JavaScript: The Future NowHTML5 & JavaScript: The Future Now
HTML5 & JavaScript: The Future Now
 
Helmi Suhaimi
Helmi SuhaimiHelmi Suhaimi
Helmi Suhaimi
 
Bb Security
Bb SecurityBb Security
Bb Security
 
Session4 pl online_course_30_september2011
Session4  pl online_course_30_september2011Session4  pl online_course_30_september2011
Session4 pl online_course_30_september2011
 
Boot to Gecko – The Web as a Platform
Boot to Gecko – The Web as a PlatformBoot to Gecko – The Web as a Platform
Boot to Gecko – The Web as a Platform
 
Talent Development Consulting C P
Talent  Development  Consulting  C PTalent  Development  Consulting  C P
Talent Development Consulting C P
 
2012.04.05 Learning Sessions #1: CityArtWorks + Mercury
2012.04.05 Learning Sessions #1: CityArtWorks + Mercury2012.04.05 Learning Sessions #1: CityArtWorks + Mercury
2012.04.05 Learning Sessions #1: CityArtWorks + Mercury
 
Yahoo pipes
Yahoo pipesYahoo pipes
Yahoo pipes
 
66条禅语,茶具欣赏feeling dhyana words and tea
66条禅语,茶具欣赏feeling dhyana words and tea66条禅语,茶具欣赏feeling dhyana words and tea
66条禅语,茶具欣赏feeling dhyana words and tea
 

Ähnlich wie PHP Underground Session 1: The Basics

P H P Part I, By Kian
P H P  Part  I,  By  KianP H P  Part  I,  By  Kian
P H P Part I, By Kian
phelios
 
MIND sweeping introduction to PHP
MIND sweeping introduction to PHPMIND sweeping introduction to PHP
MIND sweeping introduction to PHP
BUDNET
 
Php introduction with history of php
Php introduction with history of phpPhp introduction with history of php
Php introduction with history of php
pooja bhandari
 

Ähnlich wie PHP Underground Session 1: The Basics (20)

IT2255 Web Essentials - Unit IV Server-Side Processing and Scripting - PHP.pdf
IT2255 Web Essentials - Unit IV Server-Side Processing and Scripting - PHP.pdfIT2255 Web Essentials - Unit IV Server-Side Processing and Scripting - PHP.pdf
IT2255 Web Essentials - Unit IV Server-Side Processing and Scripting - PHP.pdf
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
 
P H P Part I, By Kian
P H P  Part  I,  By  KianP H P  Part  I,  By  Kian
P H P Part I, By Kian
 
MIND sweeping introduction to PHP
MIND sweeping introduction to PHPMIND sweeping introduction to PHP
MIND sweeping introduction to PHP
 
php programming.pptx
php programming.pptxphp programming.pptx
php programming.pptx
 
php app development 1
php app development 1php app development 1
php app development 1
 
Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
 
slidesharenew1
slidesharenew1slidesharenew1
slidesharenew1
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Introduction in php
Introduction in phpIntroduction in php
Introduction in php
 
php fundamental
php fundamentalphp fundamental
php fundamental
 
Php introduction with history of php
Php introduction with history of phpPhp introduction with history of php
Php introduction with history of php
 
php
phpphp
php
 
05php
05php05php
05php
 
Prersentation
PrersentationPrersentation
Prersentation
 
PHP Introduction and Training Material
PHP Introduction and Training MaterialPHP Introduction and Training Material
PHP Introduction and Training Material
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
unit 1.pptx
unit 1.pptxunit 1.pptx
unit 1.pptx
 

Mehr von Robin Hawkes

Mobile App Development - Pitfalls & Helpers
Mobile App Development - Pitfalls & HelpersMobile App Development - Pitfalls & Helpers
Mobile App Development - Pitfalls & Helpers
Robin Hawkes
 
Mozilla Firefox: Present and Future - Fluent JS
Mozilla Firefox: Present and Future - Fluent JSMozilla Firefox: Present and Future - Fluent JS
Mozilla Firefox: Present and Future - Fluent JS
Robin Hawkes
 
The State of HTML5 Games - Fluent JS
The State of HTML5 Games - Fluent JSThe State of HTML5 Games - Fluent JS
The State of HTML5 Games - Fluent JS
Robin Hawkes
 
MelbJS - Inside Rawkets
MelbJS - Inside RawketsMelbJS - Inside Rawkets
MelbJS - Inside Rawkets
Robin Hawkes
 
Melbourne Geek Night - Boot to Gecko – The Web as a Platform
Melbourne Geek Night - Boot to Gecko – The Web as a PlatformMelbourne Geek Night - Boot to Gecko – The Web as a Platform
Melbourne Geek Night - Boot to Gecko – The Web as a Platform
Robin Hawkes
 
Hacking with B2G – Web Apps and Customisation
Hacking with B2G – Web Apps and CustomisationHacking with B2G – Web Apps and Customisation
Hacking with B2G – Web Apps and Customisation
Robin Hawkes
 

Mehr von Robin Hawkes (20)

ViziCities - Lessons Learnt Visualising Real-world Cities in 3D
ViziCities - Lessons Learnt Visualising Real-world Cities in 3DViziCities - Lessons Learnt Visualising Real-world Cities in 3D
ViziCities - Lessons Learnt Visualising Real-world Cities in 3D
 
Understanding cities using ViziCities and 3D data visualisation
Understanding cities using ViziCities and 3D data visualisationUnderstanding cities using ViziCities and 3D data visualisation
Understanding cities using ViziCities and 3D data visualisation
 
Calculating building heights using a phone camera
Calculating building heights using a phone cameraCalculating building heights using a phone camera
Calculating building heights using a phone camera
 
Understanding cities using ViziCities and 3D data visualisation
Understanding cities using ViziCities and 3D data visualisationUnderstanding cities using ViziCities and 3D data visualisation
Understanding cities using ViziCities and 3D data visualisation
 
ViziCities: Creating Real-World Cities in 3D using OpenStreetMap and WebGL
ViziCities: Creating Real-World Cities in 3D using OpenStreetMap and WebGLViziCities: Creating Real-World Cities in 3D using OpenStreetMap and WebGL
ViziCities: Creating Real-World Cities in 3D using OpenStreetMap and WebGL
 
Beautiful Data Visualisation & D3
Beautiful Data Visualisation & D3Beautiful Data Visualisation & D3
Beautiful Data Visualisation & D3
 
ViziCities: Making SimCity for the Real World
ViziCities: Making SimCity for the Real WorldViziCities: Making SimCity for the Real World
ViziCities: Making SimCity for the Real World
 
The State of WebRTC
The State of WebRTCThe State of WebRTC
The State of WebRTC
 
Bringing Cities to Life Using Big Data & WebGL
Bringing Cities to Life Using Big Data & WebGLBringing Cities to Life Using Big Data & WebGL
Bringing Cities to Life Using Big Data & WebGL
 
Mobile App Development - Pitfalls & Helpers
Mobile App Development - Pitfalls & HelpersMobile App Development - Pitfalls & Helpers
Mobile App Development - Pitfalls & Helpers
 
Mozilla Firefox: Present and Future - Fluent JS
Mozilla Firefox: Present and Future - Fluent JSMozilla Firefox: Present and Future - Fluent JS
Mozilla Firefox: Present and Future - Fluent JS
 
The State of HTML5 Games - Fluent JS
The State of HTML5 Games - Fluent JSThe State of HTML5 Games - Fluent JS
The State of HTML5 Games - Fluent JS
 
HTML5 Technologies for Game Development - Web Directions Code
HTML5 Technologies for Game Development - Web Directions CodeHTML5 Technologies for Game Development - Web Directions Code
HTML5 Technologies for Game Development - Web Directions Code
 
MelbJS - Inside Rawkets
MelbJS - Inside RawketsMelbJS - Inside Rawkets
MelbJS - Inside Rawkets
 
Melbourne Geek Night - Boot to Gecko – The Web as a Platform
Melbourne Geek Night - Boot to Gecko – The Web as a PlatformMelbourne Geek Night - Boot to Gecko – The Web as a Platform
Melbourne Geek Night - Boot to Gecko – The Web as a Platform
 
Hacking with B2G – Web Apps and Customisation
Hacking with B2G – Web Apps and CustomisationHacking with B2G – Web Apps and Customisation
Hacking with B2G – Web Apps and Customisation
 
MDN Hackday London - Open Web Games with HTML5 & JavaScript
MDN Hackday London - Open Web Games with HTML5 & JavaScriptMDN Hackday London - Open Web Games with HTML5 & JavaScript
MDN Hackday London - Open Web Games with HTML5 & JavaScript
 
Geek Meet - Boot to Gecko: The Future of Mobile?
Geek Meet - Boot to Gecko: The Future of Mobile?Geek Meet - Boot to Gecko: The Future of Mobile?
Geek Meet - Boot to Gecko: The Future of Mobile?
 
HTML5 Games - Not Just for Gamers
HTML5 Games - Not Just for GamersHTML5 Games - Not Just for Gamers
HTML5 Games - Not Just for Gamers
 
NY HTML5 - Game Development with HTML5 & JavaScript
NY HTML5 - Game Development with HTML5 & JavaScriptNY HTML5 - Game Development with HTML5 & JavaScript
NY HTML5 - Game Development with HTML5 & JavaScript
 

Kürzlich hochgeladen

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
SoniaTolstoy
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Kürzlich hochgeladen (20)

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 

PHP Underground Session 1: The Basics

  • 1. Underground PHP  by Rob Hawkes i7872333@bournemouth.ac.uk
  • 3. What the sessions are ✽ Somewhere to admit lack of understanding ✽ Covering areas missed in workshops ✽ Helping you understand programming theory – critical! ✽ Focussing on the “why” over “how” ✽ A launch pad for further learning
  • 4. And what they aren’t ✽ Quick fix for The Station • Will provide examples of when to use techniques in context • Will not provide code to copy & paste ✽ Easy • PHP takes time & effort to learn
  • 5. These go without saying ✽ Provide your own equipment • We might not always be in the labs • I can’t provide individual web space ✽ Don’t piss about • Please only come if you genuinely want to learn • I won’t waste my time or yours
  • 7. Session 1: The Basics
  • 8. What we’ll cover ✽ An introduction to PHP ✽ Where to get help when you’re stuck ✽ Best practice when coding ✽ Fundamental knowledge
  • 10. What is PHP? ✽ Stands for PHP: Hypertext Preprocessor • Yes, a recursive acronym. Funky! ✽ Run directly on the web server • Windows, Linux, and Mac ✽ Makes web pages dynamic • Calculations, database interaction, etc. ✽ Latest version is PHP 5 • Introduces features not supported in PHP 4
  • 11. Basic PHP process User's Browser Web Server (Apache) PHP Engine MySQL Database
  • 12. Where to get help
  • 13. Online help ✽ Official PHP documentation • php.net ✽ Stack Overflow • stackoverflow.com ✽ SitePoint forums • sitepoint.com/forums ✽ Google
  • 14. Offline help ✽ Don’t look at me • Would love to but I don’t have the time ✽ Books • PHP and MySQL for Dynamic Web Sites • PHP and MySQL Bible
  • 16. Indentation & spacing ✽ Neat & tidy ✽ Makes code readable ✽ Less prone to error ✽ Easier to debug in future
  • 17. Indentation & spacing Unindented Indented <?php <?php $array=array(‘1’,‘2’,‘3’,‘4’,‘5’); $array = array(‘1’, ‘2’, ‘3’, ‘4’, ‘5’); $count=count($array); $count = count($array); for($i=0;$i<$count;$i++){ if($i==2){ for ($i = 0; $i < $count; $i++) { echo $array[$i]; if ($i == 2) { } echo $array[$i]; } } ?> } ?>
  • 18. Unindented Indented
  • 19. Comment everything ✽ // comments a single line ✽ /* text */ comments multiple lines ✽ Helps with learning ✽ Make comments meaningful • Explain in detail exactly what the code does ✽ Saves time when debugging ✽ Will save your arse many times
  • 20. Naming conventions ✽ camelCase • Always start with a lowercase letter • Capitalise the first letter of any further words ✽ Meaningful names • ShowProfile() rather than function1() • Makes code readable at a glance
  • 21. Further reading ✽ Zend Framework coding standards • http://framework.zend.com/manual/en/coding- standard.html
  • 23. General syntax ✽ Wrap all PHP within <?php and ?> tags • Tells server that the code within is to be run through the PHP system ✽ End every line with a semicolon; • Ok, not every line but enough to use that rule • Lets the PHP system know where a line of code ends • Most rookie errors are caused by forgetting semicolons
  • 24. General syntax ✽ Use $variables to store data for later • Variables are always preceded with a $ symbol • They can’t begin with a number • Any type of data can be stored inside a variable ✽ Echo and print • Used to output data to the browser • Negligible difference in performance between the two • Most programmers use echo
  • 25. Data types Name Short name Notes Boolean bool Truth value, either true or false Integer int Whole number (eg. 5) Floating point float / double Decimal fraction (eg. 1.7) String str Series of characters, usually text, enclosed in quotation marks Array arr Used to store multiple pieces of data in one place
  • 26. Assignment operators Operator Example Notes = $a = 1+4; Assigns the left operand (variable) to the value on the right += $a += 5 Adds the value on the right the existing value of $a -= $a -= 5 Subtracts the value on the right from the existing value of $a .= $a .= ‘Hello’ Appends the value on the right to the existing value of $a, mainly used with strings
  • 27. Arithmetic operators Operator Name Notes -$a Negation Opposite / reverse of $a $a + $b Addition Sum of $a and $b $a - $b Subtraction Difference of $a and $b $a * $b Multiplication Product of $a and $b $a / $b Division Quotient of $a and $b $a % $b Modulus Remainder of $a divided by $b
  • 28. Comparison operators Operator Name Notes $a == $b Equal True if $a is equal to $b $a === $b Identical True if $a is equal to $b, and are of the same data type $a != $b Not equal True if $a is not equal to $b $a !== $b Not identical True if $a is not equal to $b, or they are not of the same data type $a < $b Less than True if $a is less than $b $a > $b Greater than True if $a is greater than $b $a <= $b Less than or True if $a is less than or equal to $b equal to $a >= $b Greater than or True if $a is greater than or equal to equal to $b
  • 29. Increment & decrement Operator Name Notes ++$a Pre-increment Increase $a by one then return $a $a++ Post-increment Return $a then increase $a by one --$a Pre-decrement Decrease $a by one then return $a $a-- Post-decrement Return $a then decrease $a by one
  • 30. Logic operators Operator Name Notes $a and $b And True if both $a and $b are true $a && $b And True if both $a and $b are true $a or $b Or True if $a or $b is true $a || $b Or True if $a or $b is true $a xor $b Xor True if $a or $b is true, but not both !$a Not True if $a is not true
  • 31. Operator roundup ✽ PHP uses the same operators as most major programming languages ✽ = does not mean ‘equal to’ • = is used to assign a value • == means ‘equal to’
  • 32. Further reading ✽ PHP.net data types documentation • http://www.php.net/manual/en/ language.types.intro.php ✽ PHP.net operator documentation • http://www.php.net/manual/en/ language.operators.php ✽ PHP.net type comparison tables • http://www.php.net/manual/en/ types.comparisons.php