Skip Navigation

PHP Cheat Sheet (V1)

There is a newer version of this cheat sheet!

The PHP cheat sheet is designed to be printed on an A4 sheet of paper and live by a developers desk, to make life a bit easier. A description of what is on the cheat sheet follows, or if you are impatient, you can go straight to the full size PHP cheat sheet.

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". The side 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.

SuperGlobals

Thumbnail highlighting superglobals list. In PHP, SuperGlobals are available at any point in a script, and allow access to data from the user and session date, as well as information about server settings and environmental data. This section contains a list of SuperGlobal variable names.

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.

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.

Function Argument Orders

Thumbnail highlighting function argument ordering. One of the other major inconsistencies in PHP is function argument ordering. Functions that are very very similar often completely opposite ordering of arguments. This section simply lists a few of the common ones people are sometimes confused by, or that people find easy to forget.

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.

Download

So now that you know what it does, please feel free to print out the PHP cheat sheet:

Please note: If you wish to link to the PHP cheat sheet from elsewhere, please link to this page so others find the description, rather than linking directly to the sheet.

And finally, 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 nice - I'm very grateful!

177 comments

 United States #1: April 22, 2005
This is excellent. Thanks a ton.
WoW! What a beautiful sheet!
An italian translation can be found on my site here:
http://www.dapuzz.com/script/index.php?action=schema_php
with the images just taken here and many links to this article. If somethigs is wrong contact me: mail@dapuzz.com
Thanks!
Thanks very much for this. I'm forever going to php.net to look up things like this, especially the date formatting.
Thanks, all of you - glad you like it!

If you (or anyone else) have any suggestions for improvements, please do volunteer them.
 United Kingdom #5: April 22, 2005
Thanks, this is so useful!
Hey, that is nice. Thanks for letting me know about this.
 United States #7: April 24, 2005
You're the man now, dog.

It's things like this that make me question why kids can't use cheatsheets in class.
if this cheat sheet is not great, i don't know what it is then.
thx man !!!!
Absolutely awesome!!

Any chance of seeing it in PDF or PS format?
does anyone know of an asp equiv???
Chris
United Kingdom #11: April 26, 2005
Thanks for putting this together!

I'd like to get it in print quality PDF if possible too.
it's me again, i would like to tell you that i'll translate the cheatsheet into Indonesian
Danilo
Germany #13: April 26, 2005
A pdf would be great.
Re: if you're going to link to this...

You meant like this?

http://loadaveragezero.com/app/drx/Programming/Languages/PHP#IloveJD:cheatsheet

Nice work Dave. ;-)
I really think a PDF version would be nice.
Or did someone mention that allready? :)

It would make for a better printout and even better if you create it from Illustrator it can be imported again by other making it easier to get transalted versions as well.

ps: can u drop me a mesaage on my blog or something when you have a PDF version? would be great.
Scott
United States #16: April 27, 2005
"Daylight saving" has no trailing "s".
Could we pleeeease get the original graphic document (Photoshop, etc.) you used to make this?

As others have said, it'd be great to make a print-quality PDF out of this.

Also, the oft-forgotten information for one person may not match that of another; it'd be nice to customize this for our own, personal brain damage.

In any case, thanks for the resource!
Bruce Boughton
United Kingdom #18: April 27, 2005
Nice cheat sheet! By the way, for those mentioning going to php.net to see the documentation, there's downloadable formats too: http://www.php.net/download-docs.php The CHM format is especially useful on Windows!
I'm working on a selection of other formats for download, so that translations and changes are easier. I'll have a high quality copy up as well for better printing, hopefully all this week.
Anonymous
United States #20: April 27, 2005
nice job, any change of making this a PDF?
Chris
United Kingdom #21: April 27, 2005
Thanks Dave, looking forward to it.
 United States #22: April 28, 2005
Wow, very nice, thank you :-)
Wonderful - thanks! Now how about a PDF version that would print out crisply?
Sweet. Consider it linked to (and printed)!
Somethings is changed since the 22-04 but i have printed the original one (i love it) :D Why not alert users by feed on modify events?
Nicely done- missing are the ungreedy regexp modifiers:

a+?
a*?
Dapuzz: Yes, I added the superglobals since the original version, and cleaned up a few things. I'm working on a new backend for the site from scratch, and subscription to updates and so on are all planned. It's going to take a while though! :)

andig: The "+" for one or more and "*" for zero or more are both listed in the regex section. Is that what you meant?
 United Kingdom #28: April 30, 2005
I am liking this, I spend almost as much time checking up functions that I'm not totally sure how to spell as I do actually coding. I'm not really sure "Cheat Sheet" is the best name for it though I would have thought "Help Sheet" would be a more fitting name...

Why do you want a PDF version? PNG is the best way to do it, for PDF you need a PDF reader, for PNG all you need an up do date browser...
 United States #29: May 1, 2005
Very handy! You have an excellent site with lots of essential information. I appreciate your good work.
It's very, handy - thanks!

But it would be a lot better if it were not an image* but an actual HTML page with a proper print stylesheet: that way it wouldn't print so bad on low-resolution printers. The fuzzy anti-aliased text looks really bad now and some small details like superscript for notes are not discernable at all.

Text-as-image is never a good idea, but a really bad choice if it's intended to be printed.
 United Kingdom #31: May 3, 2005
Man you have been busy!

Thanks for this!
Awesome! It's nice to actually have things like these available as a printed version :)
It would be really great if you could add the parameters for the functions. Maybe not all but, the one that were not optional.
PDF is now up, as requested :)
Wes
United Kingdom #35: May 24, 2005
This is great, got it printed on A3 and stuck up on the wall!

Another handy function order (which I'm always forgetting anyway) would be substr, and maybe ucfirst and and ucwords in the string functions list.
Megathanx!
 United States #37: June 23, 2005
very cool, but the link to the pdf is broken :/
This is pretty impressive - not least because it's so short!!

I was expecting to have a handful of sheets to print out - not one single handy sheet of A4 - as this is. :)

Anyway, thanks for the time with it. :)
Kevin
Singapore #39: July 21, 2005
Thanks, man.
yushchenko
Ukraine #40: July 27, 2005
good job, Billy Boy!

find out soon an ukrainian translation on php.com.ua !



Anatolij Dobrosynets
Excellent, thanks..
Oh man Dave, have you seen this?

http://www.sitepoint.com/books/xml1/poster.php

$10 US. lol
>> a+?
>> a*?

> andig: The "+" for one or more and
> "*" for zero or more are both listed
> in the regex section. Is that what
> you meant?

No, he meant the use of the ? to make the + and * quantifiers ungreedy.
Ahhh, of course! The curse of the question mark, I suppose.

No, the ungreedy modifier is missing, as are lookahead and lookbehind assertions and so on. When creating the sheet, space was obviously at a premium so some items were cut from it. That included for the most part things that I felt were not likely to be looked up. People generally like to use a Regex aid when starting out, but by the time they understand greediness and assertions, they've usually been using regular expressions long enough that they don't need to look up things like that any more. Hopefully.
Thanks for your affords, great work!

By the way I am not good at these kind of print things. My question is that which format wil do me good for printing, PDF or PNG ?
 United Kingdom #46: October 12, 2005
Give yourself a pat on the back - really nice of you to give this away. It will be hanging on the wall above my computer :-)
Travis
United States #47: October 28, 2005
Right on man, great PHP resource!
wow, thatz's very nice. i immediately printed it :)
 Russian Federation #49: November 15, 2005
Thanks very much for this Cheat Sheet.
Great stuff!
Ayas
Indonesia #51: December 4, 2005
Just one word. "Wow"
Lazyleg
Norway #52: December 28, 2005
would it be possible to make it customizable so a user can organize the cheat sheet and get a updated vs of the sheet for printing/dl. it should be possible to do this with php.
MaR
Lithuania #53: December 30, 2005
Good job! Printed all you cheat sheets :)
I've been php developing for 3 years now and never once thought of making one of these. I printed 10 copies off straight away on works laser printer. Haha. Thanks mate!

Jeremy Child
Australia
Hi, thanks a ton! I'm gonna need your cheat sheets a LOT at my new job.

( Still, PHP sux :P )

Best wishes & keep up the great work,
Tobias Hoffmann
w00f
Romania #56: March 25, 2006
Perfect ;)
 United States #57: April 19, 2006
Thank you. I downloaded your CSS CS, and was surprised to find that you had done the same for PHP, which I just started learning. Again, thanks.
Thanx buddie. I'm a neewbie to this and it's such a help. Will have mine laminated.
Hi @all

The pdf of css Syntax ist very good.
The File ist a nice help for my next Projekt.

Sorry my EN is ;-(
Hi Dave,

@ many people have trouble with regular expressions!
and i also.
hey guys,
we all drink jacky in our travel agency after work,
for football we drink all the day so work is fun.
if you travel over us, we serve jacky for english people
Hi;)
i also got trouble with regular epressions;/ hehe
Why do you all have trouble? Do not drink so much alcohol...look at me...I only can write my name when get drunk.. :-)

Jennifer
I've been using your cheat sheet for awhile and it's really great. I use the date formating section the most.

Two function that would be great to have on the list are intval and strval.
i'm a freelance webmaster and your cheat list is a great help for my work!!, thanks!!!!!!!!!
Just a quick note, under "Date Formatting" there is an error in the ordinal suffix (S), it states "st, nd, td, th" when it should be "st, nd, rd, th" as there is no "thitd" of a month. I'm not trying to be picky, these cheat sheets are a lifesaver as they show which order certain PHP functions are written in. I just thought I'd point it out.

Cheers.
David
Jon
United Kingdom #67: August 23, 2006
THanks a lot, although I'd love a few more PHP - related cheatsheets if you could manage it. This is great for remembering things, but some more detailed ones for more complicated functions would rule.

And CSS - I can never work that thing out, but that's a different topic.
Nick
United States #68: September 3, 2006
You are a god among men. A bunch of $2 picture frames, and the office wall is a handy reference chart.
hasnat
Pakistan #69: October 13, 2006
you should have added function parameters too :/
but i still love it
PHP is one of my favorite languages...it's about time we have a quick reference for it!
This cheat sheet collection is the best set of quick references I've found on the web. Great job! I've got all of them printed and laminated, and I use at least one of them every day. :)
Wonderful, a nice job, thank you :-)
hi ,
wonderfull idea /Job ,Really thank u especillay for your valuable work!
What can I say? Nice job! Thank you for all the cheatsheets you've done!

Take care!
Fantastic documentation, a valuable resource!
Hy,
beautifull Side and nice comments.
Jack Daniels is the best Whisky of the time.
Dean
Very good article.
It's help me.
Industrial Flooring
United Kingdom #79: January 17, 2007
Fantastic tool - we've used this cheatsheet extensivley on our new site and it's one of the best out there.
the php cheat is really usefull, it really help me develop www.kid-safe.co.uk I am not a big time php user but this made things much easier.
 Russian Federation #81: February 7, 2007
Give yourself a pat on the back - really nice of you to give this away. It will be hanging on the wall above my computer :-)
This is very NICE!
Thanks!
Thanks very much !!!
Thanx for sharing.
Now I can easily access all the functions I need at the right time, I'm planning to make a poster of it, so that I can hang in the wall.
Hi,
I also really think a PDF version would be nice.

Thanks,
Florian
great job as usual. This one little page has alot of info!
Great, thank you!
Useful!
Thank you very much!
Thank you for the great article. Greetings from Germany.
Excelente articulo.

Gracias.
www.macroweb.ws
programacion web
Thank you for article from Ukraine.
Hi Dude,
The PHP cheat is really heplful !!!!
Pdamaso
Philippines #93: March 23, 2007
Hi,

THis is great! However, the pdf contains only 1 page?! (function list) where can I get the others.
Thanks
Hi Pdamaso. The cheat sheet is just one page, with everything on it. It's designed that way, to be a simple, small reference rather than a complete guide.
This is pretty impressive - not least because it's so short!
It,s a super site
gitti from germany
nice and thanks!
Jacky is the best you can drink in this world. I love this to :D
NICE!. and i'm #100 :D
Thanks for very interesting article. btw. I really enjoyed reading all of your posts. It’s interesting to read ideas, and observations from someone else’s point of view… makes you think more. I think these blog is really useful for new comers and Excellent resource list.
It´s a very interesting Blog and simple answer of many questions.
Newbie
Philippines #101: June 21, 2007
Very helpful cheat sheets with clean crisp layout. Thanks mate :)
Hello,
super site, keep on doing, kind regards from germany,
Thomas
Yeah, this site is great. Jack Daniels: all I need! :)
Thanks for the sheet
 United States #105: July 24, 2007
Jack Daniels is the best drink in the world
Arthur
Germany #106: August 6, 2007
And Vodka is the best food in the World
Johan, Philippines
Unknown #107: August 18, 2007
thanks mate!
Awesome, thanks heaps. My memory isn't the best these days and this saves trips to php.net :)
i love jack daniel too :)
Hey, I love your Cheat Sheets including this PHP one I have many a time forgotten a simple function that I have been able to find quickly using your cheat sheets, I must say these are the best free cheat sheets I could find.

I even posted on my blog about your cheat sheets: http://oysblog.uni.cc/2007/08/31/cheat-sheets/
I dont like to use php, but it is a very interesting Article.
Thanks for very interesting article. btw. I really enjoyed reading all of your posts. It’s interesting to read ideas, and observations from someone else’s point of view… makes you think more.
Thank you for the nice article.

Greetings from Germany
Jack Daniels on the rocks. hmmm
and coca Cola very nice.hhhhmmmmmm
i love jack daniel too :)
I think it ist ok, but i would be happy, if i can get it in pdf.
very handy. thanks mate!
i love it.
Thanks for this helpul article. I just downloaded your CSS CS, and was surprised to see that you had done the same thing for PHP, which I just begin to learn. So - thanks again and best regards.
Now your PHP CS is hanging in my office!
great, very hand..can we have a cheat sheet for Actionscript
Good job Dave, as usual. You da man.
Jess
Thanks for the cheat sheet. It was exactly what I was looking for to help make getting up to speed with PHP much easier. FYI: Your post came up as the first search result from Google. I love it when just what I want comes up first. Thanks again.
yeeeeaaaah! great sheet, good job!
Thanks for the cheatsheet. Will surely save me lot of time. Much appreciated.
thanks for this helpfully article
It's very cool dude! thanks

It would be nice to find an spot for reserved $_SERVER[] indexes. I always go to php.net looking for that too. :)

Thanks again
ramesh
Unknown #129: November 28, 2007
thanks! its very helpful to me and everyone
this is very good cheet sheet and very helpful to every one.

thanks !!
This sheet is great. Good work.
Well, great job, great cheat, but the function parameters will be amazing.

Thanks!
Looks ever so good, yet I cannot download the PDF (it says that the file is impartial or corrupt).
Actually, I lied it doesn't say that it is corrupt it says that the PDF file attempted to call a function that hadn't been implemented and that was because my browser keeps playing up and Acrobat was trying to display the PDF file in my browser, I just had to download it to fix it. Sorry, my mistake.
I prefer Vodka + Red Bull. But Jack Daniels on the rocks I like too. Are different Drinks.
This sheet is very well. Have done a good job.
wolfgang
Germany #137: December 15, 2007
Thanks again!
Wolfgang
This impressive piece of work is really, really helpful and saves a lot of time. Thanks for that.
Thanks for the cheat sheet - it has been a great help. Keep up the good work.
 Republic Of Moldova #140: January 4, 2008
Thank You Jack! It is really useful!

Alex from Moldova
Awesome sheet. Very helpful Thanks!
Great and useful Cheat Sheet!

Àlex from Catalonia!
Great!
Greets from Belgium!
thats right, jacky mmmmhhhh
Frank 62