Sunteți pe pagina 1din 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

PHP String Functions

PHP Date and Time Functions

a+?

One or more, ungreedy

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

[:blank:]

Space or tab

strpos (str, needle)


strrev (str)

PHP Regular Expressions Functions

There's an excellent regular expression tester

strstr (str, needle)

ereg (pattern, str)

strtolower (str)

split (pattern, str)

strtoupper (str)

ereg_replace (pattern, replace, str)

Pattern Modifiers

substr (string, start, len)

preg_grep (pattern, arr)

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

at: http://regexpal.com/

pattern
By Dave Child (DaveChild)

Published 19th October, 2011.

Sponsored by CrosswordCheats.com

cheatography.com/davechild/

Last updated 1st July, 2014.

Learn to solve cryptic crosswords!

www.addedbytes.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

Days in month (28 to 31)

U*

Ungreedy pattern
a

am or pm

AM or PM

PHP fopen() Modes

Swatch Internet Time (000 to 999)

Read

Ordinal Suffix (st, nd, rd, th)

r+

Read and write, prepend

Write, truncate

Timezone of machine (GMT)

w+

Read and write, truncate

Timezone offset (seconds)

Write, append

GMT offset (hours) (+0200)

a+

Read and write, append

Daylight saving (1 or 0)

Leap year (1 or 0)

Seconds since Epoch

ISO 8601 (PHP 5)

* PCRE modifier

PHP Date Formatting


Y

4 digit year (2008)

2 digit year (08)

Long month (January)

Short month (Jan)

Month (01 to 12)

Month (1 to 12)

Short day name (Mon)

Long day name (Monday) (lowercase L)

Day (01 to 31)

weeks in $year.

Day (1 to 31)

The Epoch is the 1st January 1970.

12 Hour (01 to 12)

12 Hour (1 to 12)

24 Hour (00 to 23)

24 Hour (0 to 23)

Minutes (00 to 59)

Seconds (00 to 59)

Day of week (0 to 6)

Day of year (0 to 365)

Week of year (1 to 53)

(2008-07-31T18:30:13+01:00)
r

RFC 2822 (Thu, 31 Jul 2008 18:30:13 +0100)

0 is Sunday, 6 is Saturday.
Week that overlaps two years belongs to year that
contains most days of that week. Hence week
number for 1st January of a given year can be 53 if
week belongs to previous year. date("W", mktime(0,
0, 0, 12, 8, $year)) always gives correct number of

With leading zeroes

By Dave Child (DaveChild)

Published 19th October, 2011.

Sponsored by CrosswordCheats.com

cheatography.com/davechild/

Last updated 1st July, 2014.

Learn to solve cryptic crosswords!

www.addedbytes.com

Page 2 of 2.

http://crosswordcheats.com

S-ar putea să vă placă și