PHP - PowerPoint PPT Presentation

1 / 32
About This Presentation
Title:

PHP

Description:

PHP – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 33
Provided by: Horn82
Category:
Tags: php | concatenate

less

Transcript and Presenter's Notes

Title: PHP


1
PHP
  • Server Side Scripting

2
What is PHP?
  • Created by Rasmus Lerdorf in 1994
  • Personal Home Pages
  • Build extensions to HTML
  • Apache Software Foundation project
  • PHP Hypertext Preprocessor

3
PHP Advantages
  • Ease to use
  • Procedural language
  • Open Source
  • Free
  • You can add new features
  • Multiplatform
  • Unix, Windows
  • Very popular
  • Language support for databases
  • MySQL, Informix, Oracle, Sybase, etc.

4
Accessing PHP Enhanced HTML Documents
  • Client/Server Architecture
  • Enter a web address to a PHP file
  • Process the request on the Web server
  • Receive the file and interpret any HTML in the
    browser

5
Basic PHP Development Process
  • Create a PHP script and save it to a local disk
  • Use FTP to copy file to the server
  • Access your file using a browser

6
Embedding PHP Statements within HTML Documents
  • lthtmlgt ltheadgtlt/headgt
  • ltbodygt
  • lth1gtGenerating HTML from PHP lt/h1gt
  • lt? Php
  • // set up my simple table
  • print (Using PHP has ltigtsome advantageslt/igt)
  • print (ltulgtltligtSpeedlt/ligtltligt/Ease of uselt/ligt
  • ltligtFunctonalitylt/ligtlt/ulgt)
  • print (lt/ bodygtlt/htmlgt)
  • ?gt

7
Results
  • Generating HTML from PHP
  • Using PHP has some advantages
  • Speed
  • Ease of Use
  • Functionality

8
PHP Constructs
  • Most statements end with a semi-colon
  • PHP commands is case insensitive
  • PHP ignores blank spaces
  • Comments
  • // this is a comment

9
PHP Variables
  • Used to store and access data
  • First character must be a
  • Second character alpha or underscore
  • Variable names are case sensitive
  • first_num 128
  • second_num first_num

10
Arithmetic Operators
  • Addition
  • Subtraction
  • Division /
  • Multiplication
  • Remainder
  • x 14 3 (x is assigned 2)

11
String Variables
  • Fname John
  • Lname Kerry
  • Concatenate Operator
  • Name Fname . Lname
  • Produces JohnKerry
  • Name Fname . . Lname
  • Name Fname Lname

12
String Functions
  • Strlen() returns the length of the string
  • num strlen(name)
  • Trim() removes any leading/trailing blanks
  • StrtoLower StrtoUpper
  • All lower case all upper case
  • Substr(string, start, how many)
  • If how many omitted goes to end of string

13
Controlling Script Flow
  • If-Then-Else
  • Switch
  • Loops
  • For
  • While
  • Foreach

14
If-Then
  • IF statement
  • If (average gt 69)
  • Grade Pass
  • Print (Grade Grade)
  • Print Your average was average

15
If-Then
  • Boolean Operators
  • equal to
  • ! not equal to
  • lt less than
  • gt greater than
  • gt greater than or equal to
  • lt less than or equal to

16
String Comparisons
  • Strcmp() case sensitive
  • Strcsecmp() case insensitive
  • num Strcmp(first, second)
  • Positive if first gt second
  • Negative if first lt second
  • Zero if first second

17
Else clause
  • If (test expression)
  • One or more php statements
  • else
  • one or more php statements

18
Elseif
  • If (test expression)
  • PHP statement(s)
  • elseif (test expression)
  • PHP statement(s)

19
Switch
  • Switch (gender)
  • Case F
  • gender_long female
  • Print Your gender is gender_long
  • Break
  • Case M
  • PHP statements
  • Break
  • Default
  • Print Error gender code does not exits

20
For-Loop
  • For (i 0 ilt max i)
  • PHP statements

21
While-Loop
  • While (counter lt max)
  • PHP statements
  • counter

22
Logical Test Operators
  • Two or more Boolean clauses
  • and
  • or
  • ! Not
  • While (x lt 100 y lt 300)

23
Date Function
  • Date()
  • Date(D) Mon, Tue, etc
  • Date(d) numerical day of the month
  • Date(F) month in long format
  • Date(M) month in short format
  • Date(H) current hour in military format
  • See documentation for more

24
Arrays
  • Sequential Arrays keeps track of data items by
    using sequential numbers
  • Associative Array keeps track of data items by
    using character strings
  • e.g. fr, so, jr, sr

25
Sequential Arrays
  • names array(Johnson, Jones, Jackson)
  • scores array(66, 75, 80)
  • Referencing items
  • The first item is number 0
  • number scores1
  • number scoresi
  • Print(names0, names1, names2)

26
Loops and Sequential Arrays
  • courses array (Perl, PHP, C, Java)
  • For (i 0 i lt count(courses) i)
  • print (coursesi )
  • Foreach (courses as item)
  • print (item )

27
Adding/Deleting Items
  • Array_shift() removes an item from beginning of
    array
  • Array_unshift() adds an item to the beginning of
    the array
  • Array_unshift(courses,C)
  • Array_pop() removes an item from the end of the
    array
  • Array_push() adds an item to the end of the array

28
Some Useful Array Functions
  • Max()
  • Min()
  • Array_sum()
  • Sort()

29
Creating Associative Arrays
  • instructorScience Jones
  • instructorMath Smith
  • instructorEnglish Lee
  • months array(Jangt31,Febgt28,
  • Margt31,Aprgt30)
  • days monthMar
  • Indices are case-sensitive

30
Modifying Associative Items
  • Changing a data value
  • coursesMath Horn
  • Deleting an array item
  • Unset(instructorEnglish
  • Adding an array item
  • coursesPhysics Einstein
  • Cant change/rename an index name
  • Use delete/add procedures

31
Sorting Associative Arrays
  • Asort()
  • Sorts the pairs on the data values
  • Ksort()
  • Sorts the pairs on the index values

32
Loops and Associative Arrays
  • Foreach (courses as index gt item)
  • PHP statements
  • index pointer
  • item value
Write a Comment
User Comments (0)
About PowerShow.com