Php Cheat Sheet

ADVERTISEMENT

PHP Cheat Sheet
by
Dave Child (DaveChild)
via
PHP Array Functions
PHP Regular Expressions Functions
PHP fopen() Modes
array_diff (arr1, arr2 ...)
ereg (pattern, str)
r
Read
array_filter (arr, function)
split (pattern, str)
r+
Read and write, prepend
array_flip (arr)
ereg_replace (pattern, replace, str)
w
Write, truncate
array_intersect (arr1, arr2 ...)
preg_grep (pattern, arr)
w+
Read and write, truncate
array_merge (arr1, arr2 ...)
preg_match (pattern, str)
a
Write, append
array_pop (arr)
preg_match_all (pattern, str, arr)
a+
Read and write, append
array_push (arr, var1, var2 ...)
preg_replace (pattern, replace, str)
PHP Date Formatting
array_reverse (arr)
preg_split (pattern, str)
Y
4 digit year (2008)
array_search (needle, arr)
Regular Expressions Syntax
y
2 digit year (08)
array_walk (arr, function)
^
Start of string
F
Long month (January)
count (count)
$
End of string
M
Short month (Jan)
in_array (needle, haystack)
.
Any single character
m
Month ⁴ (01 to 12)
PHP String Functions
(a|b)
a or b
n
Month (1 to 12)
crypt (str, salt)
(...)
Group section
D
Short day name (Mon)
explode (sep, str)
[abc]
In range (a, b or c)
l
Long day name (Monday) (lowercase L)
implode (glue, arr)
[^abc]
Not in range
d
Day ⁴ (01 to 31)
nl2br (str)
\s
White space
j
Day (1 to 31)
sprintf (frmt, args)
a?
Zero or one of a
strip_tags (str, allowed_tags)
a*
Zero or more of a
h
12 Hour ⁴ (01 to 12)
str_replace (search, replace, str)
a*?
Zero or more, ungreedy
g
12 Hour (1 to 12)
strpos (str, needle)
a+
One or more of a
H
24 Hour ⁴ (00 to 23)
strrev (str)
a+?
One or more, ungreedy
G
24 Hour (0 to 23)
strstr (str, needle)
a{3}
Exactly 3 of a
i
Minutes ⁴ (00 to 59)
strtolower (str)
a{3,}
3 or more of a
s
Seconds ⁴ (00 to 59)
strtoupper (str)
a{,6}
Up to 6 of a
substr (string, start, len)
a{3,6}
3 to 6 of a
w
Day of week ¹ (0 to 6)
a{3,6}?
3 to 6 of a, ungreedy
z
Day of year (0 to 365)
PHP Filesystem Functions
\
Escape character
W
Week of year ² (1 to 53)
clearstatcache ()
[:punct:]
Any punctuation symbol
t
Days in month (28 to 31)
copy (source, dest)
[:space:]
Any space character
fclose (handle)
[:blank:]
Space or tab
a
am or pm
fgets (handle, len)
A
AM or PM
There's an excellent regular expression tester at:
file (file)
B
Swatch Internet Time (000 to 999)
filemtime (file)
S
Ordinal Suffix (st, nd, rd, th)
Pattern Modifiers
filesize (file)
g
Global match
file_exists (file)
T
Timezone of machine (GMT)
i *
Case-insensitive
fopen (file, mode)
Z
Timezone offset (seconds)
m&
Multiple lines
fread (handle, len)
O
GMT offset (hours) (+0200)
nbsp;*
fwrite (handle, str)
I
Daylight saving (1 or 0)
s *
Treat string as single line
readfile (file)
L
Leap year (1 or 0)
x *
Allow comments and whitespace in
pattern
PHP Date and Time Functions
U
Seconds since Epoch ³
e *
Evaluate replacement
checkdate (month, day, year)
c
ISO 8601 (PHP 5) (2008-07-31T18:30:13+
U&
Ungreedy pattern
date (format, timestamp)
01:00)
nbsp;*
getdate (timestamp)
r
RFC 2822 (Thu, 31 Jul 2008 18:30:13 +0100)
* PCRE modifier
mktime (hr, min, sec, month, day, yr)
¹ 0 is Sunday, 6 is Saturday.
strftime (formatstring, timestamp)
² Week that overlaps two years belongs to year that
contains most days of that week. Hence week
strtotime (str)
number for 1st January of a given year can be 53 if

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 2