Overview
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

A more recent (even better) version of this cheat sheet is available at Cheatography!
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
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
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
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
"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
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

A more recent (even better) version of this cheat sheet is available at Cheatography!









68 Comments
Nice improvement. Thanks for the cheatsheets, they are better now. :)
#1, Chris, United States, 2 July 2008. Reply to this.
muchas gracias
#2, clodoaldo, Unknown, 5 July 2008. Reply to this.
Love the PNGs. Great works1
#3, waro, Indonesia, 16 July 2008. Reply to this.
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.
#4, Joshua, Boston, 30 July 2008. Reply to this.
Thank you very much for this cheatsheet. It's a great improvement.
#5, Sean, Sweden, 8 August 2008. Reply to this.
Just another must have cheat sheet on my desk!
(I never could remember all those date formats..)
Thank you!
#6, Sergiu, Romania, 11 August 2008. Reply to this.
Allways getting better! Cheers!
#7, Anonymous, Portugal, 16 August 2008. Reply to this.
This one is great, printed out and nailed on my wall :)
#8, Chris, Unknown, 18 August 2008. Reply to this.
Thanks for all your wonderful cheat sheets. Its very helpful to me and everyone!
#9, Alex, Unknown, 23 August 2008. Reply to this.
Very good. Looks most useful!
Nice blog,
Matt Seymour
www.matthewseymour.co.uk
#10, Matt, Unknown, 23 August 2008. Reply to this.
Nice little sheet. Will link to your page for this.
#11, Said, Unknown, 4 September 2008. Reply to this.
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.
#12, cob, United Kingdom, 25 September 2008. Reply to this.
Its amazing!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#13, sachi, India, 13 October 2008. Reply to this.
Very Cool! Thanks!
#14, Custom PHP, United States, 12 November 2008. Reply to this.
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!!
#15, alex, United Kingdom, 12 December 2008. Reply to this.
One very beautifull document.
Thanks.
#16, vestel, Unknown, 6 January 2009. Reply to this.
These things are very handy
#17, Rimian, Australia, 11 January 2009. Reply to this.
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.
#18, Felix, Germany, 11 January 2009. Reply to this.
Ups it added a dot at the end... Here is a working link http://thefaxx.de/jquery_cheatsheet.pdf
#19, Felix, Germany, 11 January 2009. Reply to this.
How'd you get the PNGs to automatically download when you click the link?
#20, LiteralKa, Unknown, 19 January 2009. Reply to this.
@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".
#21, DaveChild, United Kingdom, 19 January 2009. Reply to this.
This version is too much easier to use!
The interface is clean...much better.
Thanks!
#22, Dentista, Brazil, 27 January 2009. Reply to this.
Cool!
Thanks for your cheat sheet
:D
#23, Electronics Guy, Australia, 8 April 2009. Reply to this.
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!
#24, Robert, Republic Of Korea, 24 April 2009. Reply to this.
Your the best. These sheets are great.
#25, Adam, Unknown, 24 April 2009. Reply to this.
My Best Cheat Sheets Ever :D
#26, home alone, AU, 30 April 2009. Reply to this.
its good thx you smua
#27, ITSbeautiful, Indonesia, 8 May 2009. Reply to this.
Fantastic cheat sheets... Most helpful !! 5 Stars !!!
#28, John, Scotland - UK, 25 May 2009. Reply to this.
now the cheats are better. When will you relase the next one ? It is alway helpfull to come to you.
#29, Rosina, Germany, 31 May 2009. Reply to this.
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
#30, James, Australia, 20 June 2009. Reply to this.
Very helpful, thank you for sharing your work.
#31, wellenreiter, Germany, 25 June 2009. Reply to this.
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!
#32, James Stillion, United States, 21 July 2009. Reply to this.
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.
#33, rapidfire, United States, 24 July 2009. Reply to this.
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
#34, Alan Walker, United Kingdom, 8 August 2009. Reply to this.
please add the http_build_query function :)
http://de3.php.net/http_build_query
#35, .A, Germany, 21 August 2009. Reply to this.
can you give me a cheat of crazycart pls....................... and tnx ........................................
#36, shenelle, Philippines, 22 August 2009. Reply to this.
please
#37, aldrin santiago, isabela, 8 October 2009. Reply to this.
finally... i found this usefull cheat sheet....
#38, doel, Indonesia, 15 October 2009. Reply to this.
I bless this day that I found a good PHP cheat sheet!
#39, Diet, Australia, 25 October 2009. Reply to this.
Must I first learn all these syntax before I can write code properly, or is something I 'll learn along the line?
#40, Kyle, Ireland, 25 October 2009. Reply to this.
not bad
#41, Anonymous, China, 30 October 2009. Reply to this.
Thanks for this sheet - very well.
#42, Biggi, Germany, 12 November 2009. Reply to this.
very handy. thanks a bunch
#43, lsag, Portugal, 16 November 2009. Reply to this.
http://addedbytes.com/cheat-sheets/download/php-cheat-sheet-v2.png
Please drop Content-Disposition: attachment...or at least link to a version without it...
http://addedbytes.com/cheat-sheets/view/php-cheat-sheet-v2.png
...(yes that's a 404 until he makes it work)...I just wanna SEE it, not download it, I just wanna open it in Firefox, look it over & THEN decide to download it or not! I doubt this will display properly...but try copy/pasting this...
javascript:'<img src=http://addedbytes.com/cheat-sheets/download/php-cheat-sheet-v2.png>'
Anyone know of a Firefox Addon to FORCE View-in-Browser (aka ignore Content-Disposition: attachment)???...if not, I'm gonna write one, I'm sick of this crap!
Why do 90% of comment forms HAVE NO PREVIEW?!?
addedbytes.com/cheat-sheets/download/php-cheat-sheet-v2.png
#44, Drop Content-Disposition: attachment, 19 December 2009. Reply to this.
Is it just me or Foxit reports this pdf damaged, while other cheat sheets work flawlessly?
#45, Heiko, 8 January 2010. Reply to this.
Great cheat sheets, they come in handy when you just cannot remember what is that switch .. thanks very much.
#46, genux, Norfolk, 8 March 2010. Reply to this.
very useful result of a good teamwork - nice one
Thx
#47, Theo, Germany, 16 March 2010. Reply to this.
Great cheat sheets, they come in handy when you just cannot remember what is that switch .. thanks very much.
#48, Sohbet odalari, sohbet, 22 March 2010. Reply to this.
Must I first learn all these syntax before I can write code properly, or is something I 'll learn along the line..
#49, Sohbet, istanbul, 30 April 2010. Reply to this.
Great post! great cheat sheet
#50, Russell, United states, 5 May 2010. Reply to this.
Thank you very much for this cheatsheet. It's a great improvement.
#51, pdf search, French, 30 June 2010. Reply to this.
Thanks for posting this!! This is great!
#52, Coder, USA, 8 July 2010. Reply to this.
These cheet sheets are awesome. One thing I might ask is if you are planning on updating it soon? The ereg functions are deprecated.
#53, arctic, 23 July 2010. Reply to this.
Thanks for making it, I like the regular expression section in particular.
#54, Derek, 29 July 2010. Reply to this.
great cheat sheet!Thanks.
#55, shaffy, india, 10 August 2010. Reply to this.
thankx post good
#56, mirc, turkiye, 12 August 2010. Reply to this.
Very well done cheat sheets! Thanks a ton for your great efforts!!
#57, Nishant, India, 8 October 2010. Reply to this.
I'd like to suggest changing the way your server presents the PDF files. If you don't *force* it to be a download, then the PDF may be visible directly in the user's web browser.
#58, Lance E Sloan, 3 November 2010. Reply to this.
Very interest post and a really good blog!
#59, JayJoe, 3 December 2010. Reply to this.
how does cheatsheet work?
#60, xeki, 30 December 2010. Reply to this.
interesante, se agradece este tipo de material muy necesarioa la hora de hechar mano a un recordatorio :)
#61, iroh, chile, 25 February 2011. Reply to this.
Very nice Article, very helpful.
#62, Gustav, Germany, 25 March 2011. Reply to this.
I really want to thank you for going through all the effort to make this sheet. I do most of my coding in dreamweaver, and it really makes my day when I have a sheet like this to do tweeks to the coding. Just know that my knowledge will grow by leaps and bounds because of the contribution you have made to the community! Thanks much!!
#63, Stef, U.S.A., 4 April 2011. Reply to this.
Thank you! Like you cheat-sheet.
#64, CT, 26 April 2011. Reply to this.
Thanks, i added your website to my link page.
I like your cheat sheets very much.
Alex
#65, Bamsta, Netherlands, 23 May 2011. Reply to this.
V1 was already great stuff. Thanx alot for the V2!
#66, --redacted--, Poland, 25 May 2011. Reply to this.
Thank you for the second Version of PHP Cheat Sheet. Very cool work.
#67, MaikF, Germany, 4 March 2012. Reply to this.
Thanks for such cheat.
i am a new PHP and MySQL programmer at NIIT Aligarh
it will definitely help me a lot
#68, gaurav, india, 24 March 2012. Reply to this.