Post on 09-Apr-2018
8/8/2019 Learning PHP, Lesson 1: An introduction to PHP
http://slidepdf.com/reader/full/learning-php-lesson-1-an-introduction-to-php 1/22
www.rorygilchrist.co.uk
Lesson 1:An Introduction to PHPRory Gilchrist
Monday, 6 December 2010
8/8/2019 Learning PHP, Lesson 1: An introduction to PHP
http://slidepdf.com/reader/full/learning-php-lesson-1-an-introduction-to-php 2/22
www.rorygilchrist.co.uk
An Introduction to PHP
✤ What is PHP?
✤ Page preprocessor
✤ Open source
✤ Application written in C
✤ Based on C syntax
✤ Uses .php file extension
✤
Created in 1995Monday, 6 December 2010
8/8/2019 Learning PHP, Lesson 1: An introduction to PHP
http://slidepdf.com/reader/full/learning-php-lesson-1-an-introduction-to-php 3/22
www.rorygilchrist.co.uk
What is a page preprocessor?
Monday, 6 December 2010
8/8/2019 Learning PHP, Lesson 1: An introduction to PHP
http://slidepdf.com/reader/full/learning-php-lesson-1-an-introduction-to-php 4/22
www.rorygilchrist.co.uk
What is a page preprocessor?
Monday, 6 December 2010
8/8/2019 Learning PHP, Lesson 1: An introduction to PHP
http://slidepdf.com/reader/full/learning-php-lesson-1-an-introduction-to-php 5/22
www.rorygilchrist.co.uk
What is a page preprocessor?
index.php
Monday, 6 December 2010
8/8/2019 Learning PHP, Lesson 1: An introduction to PHP
http://slidepdf.com/reader/full/learning-php-lesson-1-an-introduction-to-php 6/22
www.rorygilchrist.co.uk
What is a page preprocessor?
index.php index.php
Filesystem
Monday, 6 December 2010
8/8/2019 Learning PHP, Lesson 1: An introduction to PHP
http://slidepdf.com/reader/full/learning-php-lesson-1-an-introduction-to-php 7/22
www.rorygilchrist.co.uk
What is a page preprocessor?
index.php index.php
Filesystem
Monday, 6 December 2010
8/8/2019 Learning PHP, Lesson 1: An introduction to PHP
http://slidepdf.com/reader/full/learning-php-lesson-1-an-introduction-to-php 8/22
www.rorygilchrist.co.uk
What is a page preprocessor?
index.php
PHP
index.php
Filesystem
Monday, 6 December 2010
8/8/2019 Learning PHP, Lesson 1: An introduction to PHP
http://slidepdf.com/reader/full/learning-php-lesson-1-an-introduction-to-php 9/22
www.rorygilchrist.co.uk
What is a page preprocessor?
index.php
PHP
index.php
Filesystem
Monday, 6 December 2010
8/8/2019 Learning PHP, Lesson 1: An introduction to PHP
http://slidepdf.com/reader/full/learning-php-lesson-1-an-introduction-to-php 10/22
www.rorygilchrist.co.uk
What is a page preprocessor?
index.php
PHP
index.php
Filesystem
Monday, 6 December 2010
8/8/2019 Learning PHP, Lesson 1: An introduction to PHP
http://slidepdf.com/reader/full/learning-php-lesson-1-an-introduction-to-php 11/22
www.rorygilchrist.co.uk
Written in C
✤ Very widely used programming language
✤ Used to build operating systems and kernels
✤ Many adaptations (C++, C#, Objective-C, etc)
✤ PHP shares syntax with C
Monday, 6 December 2010
8/8/2019 Learning PHP, Lesson 1: An introduction to PHP
http://slidepdf.com/reader/full/learning-php-lesson-1-an-introduction-to-php 12/22
www.rorygilchrist.co.uk
Coding in PHP
✤ Must be enclosed in special PHP tags
<?php
//code goes here?>
✤ Code within tags will be processed by server
✤
PHP files can be hybrid (PHP embedded within HTML)✤ Files to be handled by PHP must have .php extension
Monday, 6 December 2010
8/8/2019 Learning PHP, Lesson 1: An introduction to PHP
http://slidepdf.com/reader/full/learning-php-lesson-1-an-introduction-to-php 13/22
www.rorygilchrist.co.uk
Structure
✤ PHP uses variables
✤ Has built in functions to assist with common tasks
✤ Support for user-made functions
✤ Version 5 onward has a full object-oriented approach
Monday, 6 December 2010
8/8/2019 Learning PHP, Lesson 1: An introduction to PHP
http://slidepdf.com/reader/full/learning-php-lesson-1-an-introduction-to-php 14/22
www.rorygilchrist.co.uk
Printing to the web page
✤ Preprocessing is done before page is returned to user
✤ Must have function to print output to web page
✤ Two basic functions for printing out to the web page
✤ echo
Monday, 6 December 2010
8/8/2019 Learning PHP, Lesson 1: An introduction to PHP
http://slidepdf.com/reader/full/learning-php-lesson-1-an-introduction-to-php 15/22
www.rorygilchrist.co.uk
First PHP application: hello world
✤ Our first application, hello world:
<?php
echo “Hello World”;
?>
✤
PHP output: Hello World
✤ PHP processes code in place
✤ Any echo statements will appear in place of the PHP code once
rocessedMonday, 6 December 2010
8/8/2019 Learning PHP, Lesson 1: An introduction to PHP
http://slidepdf.com/reader/full/learning-php-lesson-1-an-introduction-to-php 16/22
www.rorygilchrist.co.uk
Variables
Monday, 6 December 2010
8/8/2019 Learning PHP, Lesson 1: An introduction to PHP
http://slidepdf.com/reader/full/learning-php-lesson-1-an-introduction-to-php 17/22
www.rorygilchrist.co.uk
Variables
$name
Monday, 6 December 2010
8/8/2019 Learning PHP, Lesson 1: An introduction to PHP
http://slidepdf.com/reader/full/learning-php-lesson-1-an-introduction-to-php 18/22
www.rorygilchrist.co.uk
Variables
$name
Monday, 6 December 2010
8/8/2019 Learning PHP, Lesson 1: An introduction to PHP
http://slidepdf.com/reader/full/learning-php-lesson-1-an-introduction-to-php 19/22
www.rorygilchrist.co.uk
Variables
$name
<?php
$name = “Roger”;
echo $name;?>
PHP Output:
Roger
Monday, 6 December 2010
8/8/2019 Learning PHP, Lesson 1: An introduction to PHP
http://slidepdf.com/reader/full/learning-php-lesson-1-an-introduction-to-php 20/22
www.rorygilchrist.co.uk
Maths
✤ Mathematical engine
✤ Range of maths functions to aid complex programming
✤ Basic example:
<?php
$sum = 2 + 4;
echo $sum;
?>
PHP Output:
6Monday, 6 December 2010
8/8/2019 Learning PHP, Lesson 1: An introduction to PHP
http://slidepdf.com/reader/full/learning-php-lesson-1-an-introduction-to-php 21/22
www.rorygilchrist.co.uk
Lesson Notes: Syntax
✤ All PHP surrounded by <?php ?>
✤ <?php tag should NOT be preceded by whitespace
✤ Variables declared using $ and =
✤ All line endings must have ;
✤ Text strings should always be enclosed in “ “ or ‘ ’
✤ Commenting text out for documentation purposes done by either //Comment or /* Comment */
Monday, 6 December 2010
8/8/2019 Learning PHP, Lesson 1: An introduction to PHP
http://slidepdf.com/reader/full/learning-php-lesson-1-an-introduction-to-php 22/22
www.rorygilchrist.co.uk
Questions
✤ If you have any questions about this lesson or would like me to goover anything with you, please get in touch:
php@rorygilchrist.co.uk