0% found this document useful (0 votes)
105 views

Davechild PHP PDF

This document provides a cheat sheet for common PHP functions across several categories: arrays, strings, files, dates, regular expressions. It lists many commonly used functions and explains their uses and parameters in 1-3 words or short phrases. Additional notes provide more context on date formatting options and regular expression syntax and modifiers.

Uploaded by

paraggn
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views

Davechild PHP PDF

This document provides a cheat sheet for common PHP functions across several categories: arrays, strings, files, dates, regular expressions. It lists many commonly used functions and explains their uses and parameters in 1-3 words or short phrases. Additional notes provide more context on date formatting options and regular expression syntax and modifiers.

Uploaded by

paraggn
Copyright
© © All Rights Reserved
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 Expressions 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 punctuation symbol
str_replace (search, replace, str) time () [:space:] Any space character
strpos (str, needle) [:blank:] Space or tab
PHP Regular Expressions Functions
strrev (str)
There's an excellent regular expression tester
strstr (str, needle) ereg (pattern, str) at: http://regexpal.com/

strtolower (str) split (pattern, str)

ereg_replace (pattern, replace, str) Pattern Modifiers


strtoupper (str)

substr (string, start, len) preg_grep (pattern, arr) g Global match

preg_match (pattern, str) i* Case-insensitive


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 13th May, 2016. Learn to solve cryptic crosswords!
www.getpostcookie.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 replacement 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


T Timezone of machine (GMT)
w Write, truncate
Z Timezone offset (seconds)
w+ Read and write, truncate
O GMT offset (hours) (+0200)
a Write, append
I Daylight saving (1 or 0)
a+ Read and write, append
L Leap year (1 or 0)

PHP Date Formatting


U Seconds since Epoch
Y 4 digit year (2008)
c ISO 8601 (PHP 5)
y 2 digit year (08)
(2008-07-31T18:30:13+01:00)
F Long month (January)
r RFC 2822 (Thu, 31 Jul 2008 18:30:13 +0100)
M Short month (Jan)
0 is Sunday, 6 is Saturday.
m Month (01 to 12) Week that overlaps two years belongs to year that
n Month (1 to 12) contains most days of that week. Hence week
number for 1st January of a given year can be 53 if
D Short day name (Mon)
week belongs to previous year. date("W", mktime(0,
l Long day name (Monday) (lowercase L)
0, 0, 12, 8, $year)) always gives correct number of
d Day (01 to 31) weeks in $year.

j Day (1 to 31) The Epoch is the 1st January 1970.


With leading zeroes

h 12 Hour (01 to 12)

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 13th May, 2016. Learn to solve cryptic crosswords!
www.getpostcookie.com Page 2 of 2. http://crosswordcheats.com

You might also like