Skip Navigation

PHP Cheat Sheet (V2)

Overview

PHP Cheat Sheet Version 2 The PHP cheat sheet is a one-page reference sheet, listing date format arguments, regular expression syntax and common functions.

This is the second version of the PHP cheat sheet. The previous version can be found at http://www.addedbytes.com/cheat-sheets/php-cheat-sheet-version-1/.

If you like the cheat sheets, and want to say thanks, please consider buying me something from my Amazon Wishlist. Thankyou very much to those who have already hunted it down and sent me something - I'm very grateful!

Updates

July 31st, 2008: Some typos corrected and more examples added to date section. Thanks to Simon Hollingshead for spotting the mistakes and for the suggestions.

Downloads

The PHP Cheat Sheet is released under a Creative Commons License (Attribution, Non-Commercial, Share Alike).

Please note: If you wish to link to a cheat sheet from elsewhere, please link to this page so others find all available versions, the license and the description.

What's New?

There are a few small changes from the first version of the PHP Cheat Sheet (which you can still download if you prefer). The most obvious change may be that it now looks different. Hopefully it's now clearer and a little easier to find the information you're looking for.

The content is largely unchanged. The Superglobals list has been removed, and the "function argument orders" section has been changed. Rather than list the orders by themselves, I have expanded the function lists to include function arguments where possible as well.

Function List

Thumbnail highlighting function list. Probably the biggest problem with PHP is its inconsistency. Some function names use underscores, some don't. Some are of the form "verb object" and some are "object verb". Some use "2" instead of "to". These sections of the cheat sheet list many of the most commonly used functions in PHP and are there to provide a quick reference to check function names. These lists include arguments where possible, as PHP's argument ordering is inconsistent between similar functions.

fopen() Modes

Thumbnail highlighting fopen modes. fopen() is a widely used function and has several modes in which it can operate, depending on whether you want to read or write to a file, and what you want to do with data already in that file. This section lists those modes and what each does.

Regular Expression Syntax

Thumbnail highlighting regular expression syntax. Many people have trouble with regular expressions, and the first step to coming to grips with them is to become familiar with the various symbols used in regular expressions and their meaning. This section lists these symbols and describes their meaning.

PCRE Modifiers

Thumbnail highlighting PCRE modifiers. "PCRE" stands for "Perl Compatible Regular Expressions". In PHP, this refers to functions like "preg_replace" and "preg_split". The patterns used in these functions can have modifiers applied to them, and this section list those modifiers and what they do.

Date Formatting

Thumbnail highlighting date formatting. There are, as I'm sure you are aware, a huge number of options when it comes to date formatting, and there are few people who remember all of them. This section of the cheat sheet lists the various options, followed by a description, and an example where appropriate.

Translations

Other Formats

41 comments

 United States #1: July 2, 2008
Nice improvement. Thanks for the cheatsheets, they are better now. :)
clodoaldo
Unknown #2: July 5, 2008
muchas gracias
waro
Indonesia #3: July 16, 2008
Love the PNGs. Great works1
Great resource.

You guys should put together a RESTful web services cheatsheet for PHP. That'd be a great tool - especially when it comes remembering the curl_setopt options.
Thank you very much for this cheatsheet. It's a great improvement.
Just another must have cheat sheet on my desk!

(I never could remember all those date formats..)

Thank you!
Anonymous
Portugal #7: August 16, 2008
Allways getting better! Cheers!
This one is great, printed out and nailed on my wall :)
Thanks for all your wonderful cheat sheets. Its very helpful to me and everyone!
Very good. Looks most useful!


Nice blog,

Matt Seymour

www.matthewseymour.co.uk
Nice little sheet. Will link to your page for this.
cob
United Kingdom #12: September 25, 2008
The comment icon topright has source: http://www.addedbytes.com/images/v7/comment.png

I believe it is this which is causing an htaccess login request to appear when the page is load. Quite alarming.
Its amazing!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Very Cool! Thanks!
alex
United Kingdom #15: December 12, 2008
Hello!
I've read your PHP security from a to z: very interesting!! I got surprised on a couple of points..

Thanks for the sheets: sure they will be of help!!
One very beautifull document.

Thanks.
These things are very handy
Hi there,

I could see that many people voted for a jQuery CheatSheet and hey I just created one. So if you're interested you can download it here http://thefaxx.de/jquery_cheatsheet.pdf. You can host it here as well if you like.
Ups it added a dot at the end... Here is a working link http://thefaxx.de/jquery_cheatsheet.pdf
LiteralKa
Unknown #20: January 19, 2009
How'd you get the PNGs to automatically download when you click the link?
@LiteralKa: I use the technique outlined at http://www.dynamicdrive.com/forums/archive/index.php/t-8408.html - sets the content disposition header to "attachment".
Dentista
Brazil #22: January 27, 2009
This version is too much easier to use!
The interface is clean...much better.
Thanks!
Cool!
Thanks for your cheat sheet
:D
 Republic Of Korea #24: April 24, 2009
Thank you so much, Dave.
It will give me a shortcut for sure and I hope that this cheet sheet would make PHP world better. :)
Peace out!
Adam
Unknown #25: April 24, 2009
Your the best. These sheets are great.
My Best Cheat Sheets Ever :D
its good thx you smua
 Scotland - UK #28: May 25, 2009
Fantastic cheat sheets... Most helpful !! 5 Stars !!!
now the cheats are better. When will you relase the next one ? It is alway helpfull to come to you.
James
Australia #30: June 20, 2009
Any chance for an advanced version?

90% off that is useless for anyone who knows what they're doing.

I'm thinking:
- strip the date constants down to commonly used but unintuitive ones such as g/G/h/H, m/n/d/j
- replace the basic regex syntax with named groups, atomic groups, backreference types beyond $[number], etc.
- much fewer functions, limited to ones where there is confusion, particularly the ones that take a haystack and needle argument in differing orders
- not sure what to add in place of all that though
Very helpful, thank you for sharing your work.
James Stillion
United States #32: July 21, 2009
I'm taking a class on Wordpress and I've posted a link to here on my instructor's website to help myself and my classmates out who might need support with the PHP aspect of it. Check it here:

http://www.premiumdw.com/SCCC/itc298/customizing-a-wordpress-theme/

This cheat sheet will be such an awesome help! Thank you for this. Really, thank you!
rapidfire
United States #33: July 24, 2009
hey. i was looking at this and thought the cheat sheet was awesome. just a slight request. these days the simple "Crypt()" function is easily crackable it would be great if u could include all the encryption methods such as blowfish, md5, etc. also as i know the "die()" function is common and might need to be listed because it helps know the error when your code fails. i say these things to help improve your cheat sheet.
I find these cheat sheet far more useful then wading through loads of pages in a book, which in a lot of cases I still dont get the answer, so keep up the good work, I am looking forward to the mysql one..

All the best from Alan
please add the http_build_query function :)

http://de3.php.net/http_build_query
shenelle
Philippines #36: August 22, 2009
can you give me a cheat of crazycart pls....................... and tnx ........................................
aldrin santiago
isabela #37: October 8, 2009
please
finally... i found this usefull cheat sheet....
I bless this day that I found a good PHP cheat sheet!
Must I first learn all these syntax before I can write code properly, or is something I 'll learn along the line?
Anonymous
China #41: October 30, 2009
not bad

Post Your Comment

· Comments with keywords instead of a name have their URLs removed.
· Your email address will not be displayed or shared.

Live Comment Preview

 United States #42: 1 minute ago