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

PHP Cheat Sheet: by Via

This document provides a cheat sheet for various PHP functions organized into categories such as arrays, strings, dates, files, and regular expressions. It lists common functions like array_push(), str_replace(), date(), fopen(), and preg_match() along with brief descriptions and examples. Regular expression syntax and modifiers are also defined. The cheat sheet is intended to be a quick reference guide for PHP functions and patterns.

Uploaded by

vikram122
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)
59 views2 pages

PHP Cheat Sheet: by Via

This document provides a cheat sheet for various PHP functions organized into categories such as arrays, strings, dates, files, and regular expressions. It lists common functions like array_push(), str_replace(), date(), fopen(), and preg_match() along with brief descriptions and examples. Regular expression syntax and modifiers are also defined. The cheat sheet is intended to be a quick reference guide for PHP functions and patterns.

Uploaded by

vikram122
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 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

[:blank:]

Space or tab

strpos (str, needle)


PHP Regular Expressions Functions

strrev (str)

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 Readability-Score.com

cheatography.com/davechild/

Last updated 1st July, 2014.

Measure your website readability!

www.addedbytes.com

Page 1 of 2.

https://readability-score.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)

0 is Sunday, 6 is Saturday.

Month (1 to 12)

Week that overlaps two years belongs to year

Short day name (Mon)

Long day name (Monday) (lowercase L)

Day (01 to 31)

Day (1 to 31)

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)

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 weeks in $year.
The Epoch is the 1st January 1970.
With leading zeroes

By Dave Child (DaveChild)

Published 19th October, 2011.

Sponsored by Readability-Score.com

cheatography.com/davechild/

Last updated 1st July, 2014.

Measure your website readability!

www.addedbytes.com

Page 2 of 2.

https://readability-score.com

You might also like