PHP examples for Web Programming class
Introduction
gettype()
function
Passing form data to a server PHP script
Simple
date()
example
Simple
getdate()
and
time()
example
Global variables
How to include other files in a script
.
Flow control statements
if
statement
switch
statement
while
loop example
for
loop example
Arrays in PHP
Creating arrays element by element
.
Creating array using
array()
constructor
.
Creating string indexed arrays
.
Functions
reset()
,
current()
, and
next
.
Iterating through a string indexed array using
next()
Iterating through a string indexed array using
each()
Strings and arrays. Function
explode()
Usage of
array_push()
and
array_pop()
,
array_shift()
and
array_unshift()
functions
.
Other useful array functions in PHP
.
Sorting arrays in PHP (
view arrays to sort
)
Sorting: Example 1
.
Sorting: Example 2
.
Sorting: Example 3
.
Sorting: Example 4
.
Sorting using
usort()
function
.
Sorting multidimensional array
Files in PHP
How to read the whole file. Function
fpassthru()
.
How to read from a file
.
How to create a hit counter
.
Get some information about file
.
Regular expressions in PHP:
Play with native PHP expressions
.
Function
preg_match()
.
Function
preg_match_all()
.
Function
preg_split()
.
Play with Perl-style regular expressions
.
Illustration for the final project.
How to add a new user
.
Error handling
Syntax or compilation errors
(
source).
Semantic or runtime errors
(
source
).
Logical errors
(
source
).
Hiding error messages
.
Logging error messages into a file
.