Skip Navigation

Find cheat sheets for every topic, or make your own to share with your friends.

Visit Cheatography »

PHP Cheat Sheet (V2)

The second version of the PHP Cheat Sheet, a quick reference guide for PHP, with functions references, a regular expression syntax guide and a reference for PHP's date formating functions.

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

Cheatography
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

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

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