Crib Sheets
Home Page
Convert Units
First Aid
Physics Program
Web Programming
Special Chars. HTML PHP JavaScript Are You Human?

DigitalDan Websites
DigitalDan Sites
Hit Counter 234
Contact Details
Email address scroller
DigitalDan's Scientific Website
PHP Crib Sheet
The list is not complete, please let me know about errors and omissions.
$_COOKIEreturns array of parameters passed to current web-page via cookies
See note on Cookies
$_GETreturns array of parameters from after the ? in current web-page address
$_POSTreturns array of parameters passed to current web-page using the <form> option of post
$_SESSIONreturns array of parameters held in the SESSION array
Consider data security if information is sensitive
/* ... */comment
absAbsolute value
array_diff( .., ...)return values present in either array but not found in the other array
array_intersect( .., ...)return values present in both arrays
array_key_exists( ..., .. )returns true/false dependingon whether array ... contains the key ..
array_merge( .. , ... )merge two (or more) arrays
array_reverse( .. )Reverse the order of elements in array ..
array_unique( .. )remove duplicate entries from array ..
arraydefines a variable array
arsort( .. )Sort (descending) the array ..
asort( .. )Sort the array ..
base_convertconvert between bases
bindecbinary to decimal
breakStop a loop (for, while, do, switch etc.)
ceilround up to nearest integer
checkdatevalidate a date
classdefines a class
closedirclose directory
continueStart next pass of loop (for, while, do, etc.)
coshHyperbolic cosine
date_parseArray containing date information
date_sun_infoArray containing sunrise/sunset information
dateget information about a date
decbinDecimal to binary
dechexDecimal to hex
decoctDecimal to octal
deg2raddegrees to radians
do{ ... } while( .. );Repeat ... while .. is true
always run ... at least once
easter_datedate of easter
echoSend to browser as HTML
elseUsed as part of an If to indicate action when Not true
elseif similar to "else { if"
ereg_replaceReplace characters in a string using regular expression rules
eregApplies regular expression to string
eregi_replaceReplace characters in a string using regular expression rules (not case sensitive)
eregiApplies regular expression to string but not case sensitive
expexponent of e
expm1exp(number) - 1
fcloseclose a file
fgetcsvread data from a .csv file
fgetsread data from file
fgetsread one line of data from a file
file_exists( ... )returns true or false depending on whether the file can be found
file_get_contentscopy the entire contents of a file into a variable
file_put_contentscreate a file using the data in a variable
fileatimereturns timestamp when file last accessed
filectimereturns timestamp when file created
filegroupreturns the file group associated with a file
fileinodereturns the files inode
filemtimereturns timestamp when file last modified
fileownerreturns file owner
filepermsreturns file permissions
fileposget current position for reading/writing within a file
filesizereturns size of file (in bytes)
filetypereturns type of file
floorround down to nearest integer
fmodremainder (modulus)
fopenopen a file
for(.. = ..; ..; ..;){ .. }for ... next loop
foreach(.. as ... => ....){ ..... }Loop though every element n an array
fputcsvwrite data to file in .csv format
freadread data from file
fseekset current position for reading/writing within a file
function ..([..[,..]]) { ... }defines a function with optional parameters
fwritewrite to file
getdate( ... )break a date down in to month, year, weekday etc.
See below for parameters
getowdget owner of current directory
hexdechex to decimal
hypothypotenuse of a right-angle triangle
ifif .. then ...
include ..insert all code contained in the file ..
is_executablereturns the file attribute indicating iof it is executabe
is_filereturns true if a real file and false if a link
is_finiteis number finite
is_infiniteis number infinite
is_linkreturns true if file is a link
is_nanis not a number
is_readablereturns true if file can be read and false if unreadable
is_writeablereturns true if file can be written to
isset( .. )returns true/false depending on whether the variable exists
particularly useful with $_GET, $_POST etc.
krsort( .. )Sort (descending) the array .. into key sequence
ksort( .. )Sort the array .. into key sequence
log1plog(1 + number)
max(..,..,..)return largest number in list
maxmaximum value
min(..,..,..)return smallest number in list
minminiumum value
mktime(..,..,..,..,..,..)sets a date variable
parameters in order are hour,month,second,month,day,year
mt_rand(..,...)return random integer between .. and ...
mt_srand(..,...)return random integer between .. and ...
octdecOctal to decimal
powExponential expression
print_r( .. )output every element in array ..
printf(..)format the sting .. and print
rad2degradians to degrees
rand(..,...)return random integer between .. and ...
randrandom number (integer)
readdirread directory entry
returnReturn a value from a function
rewinddirreset directory pointer
round(..[,...])round number down to ... decimal places
nearest integer if ... ommited
roundround to nearest integer
serialize( .. )Convert array .. into a specially formatted string
Set-Cookiesets up a cookie
See note on cookies
sinhHyperbolic sine
sprintf(..)format the sting ..
uses same settings as printf shown below
sqrtSquare root
srandseed random number generator
strlen( .. )Number of characters in string ..
strpos( .., ... )position of first ... in string ..
strings start at character 0
strstr( .., ... )returns all characters in string .. after(and including) the first ...
strtotime(..)Convert dates as text into a date variable
expects US date formats, unpredictable with UK formats
substr(..,...[,....]).... letters from string .. staring at position ...
strings start at character 0
if .... omitted, all characters to end of string returned
switch (..){ case: ...; break; default: .... }Select action to take based on ..
tanhHyperbolic tangent
unserialize( .. )Convert a serialised string into an array
while( .. ){ ... }Repeat ... while .. is true
Maths Operators
%modulus (remainder)
*=..%=... equivilent to .. = .. % ...
*=..-=... equivilent to .. = .. * ...
/=..+=... equivilent to .. = .. / ...
++..++ equivilent to .. = .. + 1
++.. adds 1 before showing result
+=..+=... equivilent to .. = .. + ...
--..-- equivilent to .. = .. - 1
--.. subtracts 1 before showing result
-=..-=... equivilent to .. = .. - ...
String Operators
!=is not the same as
>is alphabetically after
>=is alphabetically the same or after
<is alphabetically before
<=is alphabetically the same or before
==is the same as
File access
a+read and write file (add to end of file if file already exists)
awrite to file (add to end of file if file already exists)
r+read and write (starting at beginning of file)
rread (starting at beginning of file)
w+read and write file (overwrite entire file if it already exists)
wwrite file (overwrite entire file if it already exists)
Conditional operators etc.
!=is not equal to
>is greater than
>=is greater than or equal to
<is less than
<=is less than or equal to
==is equal to
===is equal to and the same type of variable
exclusive or
Current date assumed if date_variable omitted
Some systems fail on dates before 1970 or after 2037
amorning/afternoon am-pm
Amorning/afternoon AM-PM
Binternet time
cfull date in ISO format
dday of month 01-31
Dday of week Sun-Sat
etime zone identifier
Fname of month January-December
Ghour 0-23
ghour 1-12
Hhour 00-23
hhour 01-12
IIs this daylight saving time
iminute 00-59
jday of month 1-31
lday of week Sunday-Saturday
Lis it a leap year?
Mmonth Jan-Dec
mmonth number 01-12
nmonth number 1-12
Nnumeric day of week
o4 digit year adjusted if weeknumber in different year
Ooffset from Greenwich Meen Time {hours}
Poffset from Greenwich Mean Time {returns hh:mm}
rfull date in RFC format
Sday on month suffix st-nd-rd-th
sseconds 00-59
tnumber of days in month
Ttimezone abbreviation
umicroseconds {needs DateTime::format()}
Useconds since 1-Jan-1980 (Unix epoch date)
wnumber for day of week 0-7 (0-Sunday, 6=Saturday)
Wweek number 0-53
ylast 2 digits of year 70-37
Yyear 1970-2037
zday of year 0-365
Ztimezone offset in seconds
getdate( .. )
hourshours 0-23
mdayday of month 0-31
minutesminutes 0-59
monmonth number 1-12
wdaynumber for day of week 0-6 (0=Sun, 6=Sat)
ydayday of year 0-365
yearyear 1970-2037
printf( .. ) format must pad to .. characters
cascii character
ffloating point
xhexadecimal (lowercase a-f)
Xhexadecimal (uppercase A-F)
Regular Expressions
.. - ...any character between .. and ... in computer alphabet
.any character
?the previous test is optional
[:alnum:]a-z, A-Z or 0-9
[:alpha:]a-z or A-Z
[:print:]all normal (printable) characters including space
[:punct:]all characters except a-z, A-Z, 0-9 and space
Cookies should be avoided whenever possible for many reasons including these... is part of the group