PHP cheatsheet

· · 531 words · 3 minute read

PHP Array Functions 🔗

PHP String Functions 🔗

PHP Filesystem Functions 🔗

PHP Date and Time Functions 🔗

PHP Regular Expres­sions Functions 🔗

Regular Expres­sions Syntax 🔗

^Start of string
$End of string
.Any single character
(…)Group section
[abc]In range (a, b or c)
[^abc]Not in range
\sWhite space
a?Zero or one of a
a*Zero or more of a
a*?Zero or more, ungreedy
a+One or more of a
a+?One or more, ungreedy
a{3}Exactly 3 of a
a{3,}3 or more of a
a{,6}Up to 6 of a
a{3,6}3 to 6 of a
a{3,6}?3 to 6 of a, ungreedy
\Escape character
[:punct:]Any punctu­ation symbol
[:space:]Any space character
[:blank:]Space or tab

Pattern Modifiers 🔗

gGlobal match
mMultiple lines
sTreat string as single line
xAllow comments and whitespace in pattern
eEvaluate replac­ement
UUngreedy pattern

PHP fopen() Modes 🔗

r+Read and write, prepend
wWrite, truncate
w+Read and write, truncate
aWrite, append
a+Read and write, append

PHP Date Formatting 🔗

Y4 digit year (2020)
y2 digit year (08)
FLong month (January)
MShort month (Jan)
mMonth (01 to 12)
nMonth (1 to 12)
DShort day name (Mon)
lLong day name (Monday) (lowercase L)
dDay (01 to 31)
jDay (1 to 31)
h12 Hour (01 to 12)
g12 Hour (1 to 12)
H24 Hour (00 to 23)
G24 Hour (0 to 23)
iMinutes (00 to 59)
sSeconds (00 to 59)
wDay of week (0 to 6)
zDay of year (0 to 365)
WWeek of year (1 to 53)
tDays in month (28 to 31)
aam or pm
BSwatch Internet Time (000 to 999)
SOrdinal Suffix (st, nd, rd, th)
TTimezone of machine (GMT)
ZTimezone offset (seconds)
OGMT offset (hours) (+0200)
IDaylight saving (1 or 0)
LLeap year (1 or 0)
USeconds since Epoch
cISO 8601 (PHP 5)(2008-­07-­31T­18:­30:­13+­01:00)
rRFC 2822 (Thu, 31 Jul 2008 18:30:13 +0100)