0% found this document useful (0 votes)
54 views2 pages

PHP Cheat Sheet: by Via

This document provides a cheat sheet for PHP with summaries of core PHP functions organized into categories like arrays, strings, dates, files, and regular expressions. It lists common PHP functions and explains their uses along with examples of date formatting codes and regular expression syntax.

Uploaded by

randrianarivo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views2 pages

PHP Cheat Sheet: by Via

This document provides a cheat sheet for PHP with summaries of core PHP functions organized into categories like arrays, strings, dates, files, and regular expressions. It lists common PHP functions and explains their uses along with examples of date formatting codes and regular expression syntax.

Uploaded by

randrianarivo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

PHP Cheat Sheet

by Dave Child (DaveChild) via cheatography.com/1/cs/2/

PHP Array Functions PHP Filesystem Functions Regular Expres​sions Syntax

array_diff (arr1, arr2 ...) clearstatcache () ^ Start of string


array_filter (arr, function) copy (source, dest) $ End of string
array_flip (arr) fclose (handle) . Any single character

array_intersect (arr1, arr2 ...) fgets (handle, len) (a|b) a or b


array_merge (arr1, arr2 ...) file (file) (...) Group section
array_pop (arr) filemtime (file) [abc] In range (a, b or c)
array_push (arr, var1, var2 ...) filesize (file) [^abc] Not in range
array_reverse (arr) file_exists (file) \s White space
array_search (needle, arr) fopen (file, mode) a? Zero or one of a
array_walk (arr, function) fread (handle, len) a* Zero or more of a
count (count) fwrite (handle, str) a*? Zero or more, ungreedy

in_array (needle, haystack) readfile (file) a+ One or more of a


a+? One or more, ungreedy
PHP String Functions PHP Date and Time Functions
a{3} Exactly 3 of a
crypt (str, salt) checkdate (month, day, year)
a{3,} 3 or more of a
explode (sep, str) date (format, timestamp)
a{,6} Up to 6 of a
implode (glue, arr) getdate (timestamp)
a{3,6} 3 to 6 of a
nl2br (str) mktime (hr, min, sec, month, day, yr)
a{3,6}? 3 to 6 of a, ungreedy
sprintf (frmt, args) strftime (formatstring, timestamp)
\ Escape character
strip_tags (str, allowed_tags) strtotime (str)
[:punct:] Any punctu​ation symbol
str_replace (search, replace, str) time ()
[:space:] Any space character
strpos (str, needle)
[:blank:] Space or tab
PHP Regular Expres​sions Functions
strrev (str)
There's an excellent regular expression
ereg (pattern, str)
strstr (str, needle) tester at: http:/​/re​gex​pal.com/
split (pattern, str)
strtolower (str)
ereg_replace (pattern, replace, str) Pattern Modifiers
strtoupper (str)
preg_grep (pattern, arr) g Global match
substr (string, start, len)
preg_match (pattern, str) i* Case-i​nse​nsitive
preg_match_all (pattern, str, arr) m* Multiple lines
preg_replace (pattern, replace, str) s* Treat string as single line
preg_split (pattern, str) x* Allow comments and whitespace in
pattern

By Dave Child (DaveChild) Published 19th October, 2011. Sponsored by CrosswordCheats.com


cheatography.com/davechild/ Last updated 29th February, 2020. Learn to solve cryptic crosswords!
aloneonahill.com Page 1 of 2. http://crosswordcheats.com
PHP Cheat Sheet
by Dave Child (DaveChild) via cheatography.com/1/cs/2/

Pattern Modifiers (cont) PHP Date Formatting (cont)

e* Evaluate replac​ement t Days in month (28 to 31)


U* Ungreedy pattern
a am or pm
* PCRE modifier
A AM or PM
PHP fopen() Modes B Swatch Internet Time (000 to 999)
r Read S Ordinal Suffix (st, nd, rd, th)
r+ Read and write, prepend
w Write, truncate T Timezone of machine (GMT)

w+ Read and write, truncate Z Timezone offset (seconds)

a Write, append O GMT offset (hours) (+0200)

a+ Read and write, append I Daylight saving (1 or 0)


L Leap year (1 or 0)
PHP Date Formatting

Y 4 digit year (2008) U Seconds since Epoch ³

y 2 digit year (08) c ISO 8601 (PHP 5) (2008-​07-​31T​18:​‐


30:​13+​01:00)
F Long month (January)
r RFC 2822 (Thu, 31 Jul 2008 18:30:13
M Short month (Jan)
+0100)
m Month ⁴ (01 to 12)
¹ 0 is Sunday, 6 is Saturday.
n Month (1 to 12)
² Week that overlaps two years belongs to
D Short day name (Mon)
year that contains most days of that week.
l Long day name (Monday) (lowercase Hence week number for 1st January of a
L) given year can be 53 if week belongs to
d Day ⁴ (01 to 31) previous year. date("W​", mktime(0, 0, 0, 12,
8, $year)) always gives correct number of
j Day (1 to 31)
weeks in $year.
³ The Epoch is the 1st January 1970.
h 12 Hour ⁴ (01 to 12)
⁴ With leading zeroes
g 12 Hour (1 to 12)
H 24 Hour ⁴ (00 to 23)
G 24 Hour (0 to 23)
i Minutes ⁴ (00 to 59)
s Seconds ⁴ (00 to 59)

w Day of week ¹ (0 to 6)
z Day of year (0 to 365)
W Week of year ² (1 to 53)

By Dave Child (DaveChild) Published 19th October, 2011. Sponsored by CrosswordCheats.com


cheatography.com/davechild/ Last updated 29th February, 2020. Learn to solve cryptic crosswords!
aloneonahill.com Page 2 of 2. http://crosswordcheats.com

You might also like