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

16 comments

 United States #1: July 2, 2008
Nice improvement. Thanks for the cheatsheets, they are better now. :)
clodoaldo
peru #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.ilovejackdaniels.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
who cares? #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.

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 #17: 1 minute ago