Example | Description |
---|---|
[a-g] | match any lowercase letter from a through g |
[0-9] | match any digit (0 through 9), equivalent to \d |
[^A-Z] | match no letters from A through Z |
(foo|bar) | match either "foo" or "bar" |
(?(condition)yes-pattern) (?(condition)yes-pattern|no-pattern) |
If the condition is satisfied, the yes-pattern is used; otherwise the no-pattern (if present) is used. |
Find practical examples of regular expressions at Regular-Expressions.info
Character | Description |
---|---|
\ | general escape cahracter with serveral uses |
^ | assert start of subject (or line, in multiline mode) or negate the class if the first character in a character class |
$ | assert end of subject (or line, in multiline mode) |
. | match any character except newline (by default) |
[ | start character class definition |
] | end character class definition |
| | start of alternative branch |
( | start subpatter |
) | end subpattern |
? | extends the meaning of (also 0 or 1 quantifier, equivalent to {0,1}, also quantifier minimizer) |
* | 0 or more quantifier, equivalent to {0,} |
+ | 1 or more quantifier, equivalent to {1,} |
{ | start min/max quantifier |
} | end min/max quantifier |
- | indicates character range in a character class |
\a | alarm, that is, the BEL character (hex 07) |
\cx | "control-x", where x is any character |
\e | escape (hex 1B) |
\f | formfeed (hex 0C) |
\n | newline (hex 0A) |
\r | carriage return (hex 0D) |
\t | tab (hex 09) |
\xhh | character with hex code hh |
\ddd | character with octal code ddd, or backreference |
\040 | is another way of writing a space |
\40 | is the same, provided there are fewer than 40 previous capturing subpatterns |
\7 | is always a back reference |
\11 | might be a back reference, or another way of writing a tab |
\011 | is always a tab |
\0113 | is a tab followed by the character "3" |
\113 | is the character with octal code 113 (since there can be no more than 99 back references) |
\377 | is a byte consisting entirely of 1 bits |
\81 | is either a back reference, or a binary zero followed by the two characters "8" and "1" |
\d | any decimal digit |
\D | any character that is not a decimal digit |
\h | any horizontal whitespace character (since PHP 5.2.4) |
\H | any character that is not a horizontal whitespace character (since PHP 5.2.4) |
\s | any whitespace character |
\S | any character that is not a whitespace character |
\v | any vertical whitespace character (since PHP 5.2.4) |
\V | any character that is not a vertical whitespace character (since PHP 5.2.4) |
\w | any "word" character |
\W | any "non-word" character |
\b | word boundary |
\B | not a word boundary |
\A | start of a subject (independent of multiline mode) |
\Z | end of subject or newline at end (independent of multiline mode) |
\z | end of subject (independent of multiline mode) |
\G | first matching position in subject |
\p{xx} | a character with xx property |
\P{xx} | a character without the xx property |
\X | an extended Unicode sequence |
(?i) | for PCRE_CASELESS |
(?m) | for PCRE_MULTILINE |
(?s) | for PCRE_DOTALL |
(?x) | for PCRE_EXTENDED |
(?U) | for PCRE_UNGREEDY |
(?X) | for PCRE_EXTRA |
Modifier | Description |
---|---|
i (PCRE_CASELESS) | If this modifier is set, letters in the pattern match both upper and lower case letters. |
m (PCRE_MULTILINE) | By default, PCRE treats the subject string as consisting of a single "line" of characters (even if it actually contains several newlines). The "start of line" metacharacter (^) matches only at the start of the string, while the "end of line" metacharacter ($) matches only at the end of the string, or before a terminating newline (unless D modifier is set). This is the same as Perl. When this modifier is set, the "start of line" and "end of line" constructs match immediately following or immediately before any newline in the subject string, respectively, as well as at the very start and end. This is equivalent to Perl's /m modifier. If there are no "\n" characters in a subject string, or no occurrences of ^ or $ in a pattern, setting this modifier has no effect. |
s (PCRE_DOTALL) | If this modifier is set, a dot metacharacter in the pattern matches all characters, including newlines. Without it, newlines are excluded. This modifier is equivalent to Perl's /s modifier. A negative class such as [^a] always matches a newline character, independent of the setting of this modifier. |
x (PCRE_EXTENDED) | If this modifier is set, whitespace data characters in the pattern are totally ignored except when escaped or inside a character class, and characters between an unescaped # outside a character class and the next newline character, inclusive, are also ignored. This is equivalent to Perl's /x modifier, and makes it possible to include comments inside complicated patterns. Note, however, that this applies only to data characters. Whitespace characters may never appear within special character sequences in a pattern, for example within the sequence (?( which introduces a conditional subpattern. |
e (PREG_REPLACE_EVAL) | If this modifier is set, preg_replace() does normal substitution of backreferences in the replacement string, evaluates it as PHP code, and uses the result for replacing the search string. Single quotes, double quotes, backslashes and NULL chars will be escaped by backslashes in substituted backreferences. Only preg_replace() uses this modifier; it is ignored by other PCRE functions. Note: This modifier was not available in PHP 3. |
A (PCRE_ANCHORED) | If this modifier is set, the pattern is forced to be "anchored", that is, it is constrained to match only at the start of the string which is being searched (the "subject string"). This effect can also be achieved by appropriate constructs in the pattern itself, which is the only way to do it in Perl. |
D (PCRE_DOLLAR_ENDONLY) | If this modifier is set, a dollar metacharacter in the pattern matches only at the end of the subject string. Without this modifier, a dollar also matches immediately before the final character if it is a newline (but not before any other newlines). This modifier is ignored if m modifier is set. There is no equivalent to this modifier in Perl. |
S | When a pattern is going to be used several times, it is worth spending more time analyzing it in order to speed up the time taken for matching. If this modifier is set, then this extra analysis is performed. At present, studying a pattern is useful only for non-anchored patterns that do not have a single fixed starting character. |
U (PCRE_UNGREEDY) | This modifier inverts the "greediness" of the quantifiers so that they are not greedy by default, but become greedy if followed by "?". It is not compatible with Perl. It can also be set by a (?U) modifier setting within the pattern or by a question mark behind a quantifier (e.g. .*?). |
X (PCRE_EXTRA) | This modifier turns on additional functionality of PCRE that is incompatible with Perl. Any backslash in a pattern that is followed by a letter that has no special meaning causes an error, thus reserving these combinations for future expansion. By default, as in Perl, a backslash followed by a letter with no special meaning is treated as a literal. There are at present no other features controlled by this modifier. |
u (PCRE_UTF8) | This modifier turns on additional functionality of PCRE that is incompatible with Perl. Pattern strings are treated as UTF-8. This modifier is available from PHP 4.1.0 or greater on Unix and from PHP 4.2.3 on win32. UTF-8 validity of the pattern is checked since PHP 4.3.5. |
Constant | Description |
---|---|
PREG_PATTERN_ORDER | Orders results so that $matches[0] is an array of full pattern matches, $matches[1] is an array of strings matched by the first parenthesized subpattern, and so on. This flag is only used with preg_match_all(). |
PREG_SET_ORDER | Orders results so that $matches[0] is an array of first set of matches, $matches[1] is an array of second set of matches, and so on. This flag is only used with preg_match_all(). |
PREG_OFFSET_CAPTURE | See the description of PREG_SPLIT_OFFSET_CAPTURE. This flag is available since PHP 4.3.0. |
PREG_SPLIT_NO_EMPTY | This flag tells preg_split() to return only non-empty pieces. |
PREG_SPLIT_DELIM_CAPTURE | This flag tells preg_split() to capture parenthesized expression in the delimiter pattern as well. This flag is available since PHP 4.0.5. |
PREG_SPLIT_OFFSET_CAPTURE | If this flag is set, for every occurring match the appendant string offset will also be returned. Note that this changes the return values in an array where every element is an array consisting of the matched string at offset 0 and its string offset within subject at offset 1. This flag is available since PHP 4.3.0 and is only used for preg_split(). |
PREG_NO_ERROR | Returned by preg_last_error() if there were no errors. Available since PHP 5.2.0. |
PREG_INTERNAL_ERROR | Returned by preg_last_error() if there was an internal PCRE error. Available since PHP 5.2.0. |
PREG_BACKTRACK_LIMIT_ERROR | Returned by preg_last_error() if backtrack limit was exhausted. Available since PHP 5.2.0. |
PREG_RECURSION_LIMIT_ERROR | Returned by preg_last_error() if recursion limit was exhausted. Available since PHP 5.2.0. |
PREG_BAD_UTF8_ERROR | Returned by preg_last_error() if the last error was caused by malformed UTF-8 data (only when running a regex in UTF-8 mode). Available since PHP 5.2.0. |
PCRE_VERSION | PCRE version and release date (e.g. "7.0 18-Dec-2006"). Available since PHP 5.2.4. |
Variable | Description |
---|---|
'PHP_SELF' | The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar. The __FILE__ constant contains the full path and filename of the current (i.e. included) file. If PHP is running as a command-line processor this variable contains the script name since PHP 4.3.0. Previously it was not available. |
'argv' | Array of arguments passed to the script. When the script is run on the command line, this gives C-style access to the command line parameters. When called via the GET method, this will contain the query string. |
'argc' | Contains the number of command line parameters passed to the script (if run on the command line). |
'GATEWAY_INTERFACE' | What revision of the CGI specification the server is using; i.e. 'CGI/1.1'. |
'SERVER_ADDR' | The IP address of the server under which the current script is executing. |
'SERVER_NAME' | The name of the server host under which the current script is executing. If the script is running on a virtual host, this will be the value defined for that virtual host. |
'SERVER_SOFTWARE' | Server identification string, given in the headers when responding to requests. |
'SERVER_PROTOCOL' | Name and revision of the information protocol via which the page was requested; i.e. 'HTTP/1.0'; |
'REQUEST_METHOD' | Which request method was used to access the page; i.e. 'GET', 'HEAD', 'POST', 'PUT'. |
'REQUEST_TIME' | The timestamp of the start of the request. Available since PHP 5.1.0. |
'QUERY_STRING' | The query string, if any, via which the page was accessed. |
'DOCUMENT_ROOT' | The document root directory under which the current script is executing, as defined in the server's configuration file. |
'HTTP_ACCEPT' | Contents of the Accept: header from the current request, if there is one. |
'HTTP_ACCEPT_CHARSET' | Contents of the Accept-Charset: header from the current request, if there is one. Example: 'iso-8859-1,*,utf-8'. |
'HTTP_ACCEPT_ENCODING' | Contents of the Accept-Encoding: header from the current request, if there is one. Example: 'gzip'. |
'HTTP_ACCEPT_LANGUAGE' | Contents of the Accept-Language: header from the current request, if there is one. Example: 'en'. |
'HTTP_CONNECTION' | Contents of the Connection: header from the current request, if there is one. Example: 'Keep-Alive'. |
'HTTP_HOST' | Contents of the Host: header from the current request, if there is one. |
'HTTP_REFERER' | The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted. |
'HTTP_USER_AGENT' | Contents of the User-Agent: header from the current request, if there is one. This is a string denoting the user agent being which is accessing the page. A typical example is: Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586). Among other things, you can use this value with get_browser() to tailor your page's output to the capabilities of the user agent. |
'HTTPS' | Set to a non-empty value if the script was queried through the HTTPS protocol. Note that when using ISAPI with IIS, the value will be off if the request was not made through the HTTPS protocol. |
'REMOTE_ADDR' | The IP address from which the user is viewing the current page. |
'REMOTE_HOST' | The Host name from which the user is viewing the current page. The reverse dns lookup is based off the REMOTE_ADDR of the user. |
'REMOTE_PORT' | The port being used on the user's machine to communicate with the web server. |
'SCRIPT_FILENAME' | The absolute pathname of the currently executing script. |
'SERVER_ADMIN' | The value given to the SERVER_ADMIN (for Apache) directive in the web server configuration file. If the script is running on a virtual host, this will be the value defined for that virtual host. |
'SERVER_PORT' | The port on the server machine being used by the web server for communication. For default setups, this will be '80'; using SSL, for instance, will change this to whatever your defined secure HTTP port is. |
'SERVER_SIGNATURE' | String containing the server version and virtual host name which are added to server-generated pages, if enabled. |
'PATH_TRANSLATED' | Filesystem- (not document root-) based path to the current script, after the server has done any virtual-to-real mapping. |
'SCRIPT_NAME' | Contains the current script's path. This is useful for pages which need to point to themselves. The __FILE__ constant contains the full path and filename of the current (i.e. included) file. |
'REQUEST_URI' | The URI which was given in order to access this page; for instance, '/index.html'. |
'PHP_AUTH_DIGEST' | When running under Apache as module doing Digest HTTP authentication this variable is set to the 'Authorization' header sent by the client (which you should then use to make the appropriate validation). |
'PHP_AUTH_USER' | When running under Apache or IIS (ISAPI on PHP 5) as module doing HTTP authentication this variable is set to the username provided by the user. |
'PHP_AUTH_PW' | When running under Apache or IIS (ISAPI on PHP 5) as module doing HTTP authentication this variable is set to the password provided by the user. |
'AUTH_TYPE' | When running under Apache as module doing HTTP authenticated this variable is set to the authentication type. |
Mode | Description |
---|---|
r | Open for reading only; place the file pointer at the beginning of the file. |
r+ | Open for reading and writing; place the file pointer at the beginning of the file. |
w | Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. |
w+ | Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. |
a | Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it. |
a+ | Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it. |
x | Create and open for writing only; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call. This option is supported in PHP 4.3.2 and later, and only works for local files. |
x+ | Create and open for reading and writing; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call. This option is supported in PHP 4.3.2 and later, and only works for local files. |
Constant | Description |
---|---|
__LINE__ | The current line number of the file. |
__FILE__ | The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, __FILE__ always contains an absolute path whereas in older versions it contained relative path under some circumstances. |
__FUNCTION__ | The function name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the function name as it was declared (case-sensitive). In PHP 4 its value is always lowercased. |
__CLASS__ | The class name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the class name as it was declared (case-sensitive). In PHP 4 its value is always lowercased. |
__METHOD__ | The class method name. (Added in PHP 5.0.0) The method name is returned as it was declared (case-sensitive). |
Constant | Description |
---|---|
PHP_VERSION (string) | |
PHP_OS (string) | |
PHP_SAPI (string) | Available since PHP 4.2.0. See also php_sapi_name(). |
PHP_EOL (string) | Available since PHP 4.3.10 and PHP 5.0.2 |
PHP_INT_MAX (integer) | Available since PHP 4.4.0 and PHP 5.0.5 |
PHP_INT_SIZE (integer) | Available since PHP 4.4.0 and PHP 5.0.5 |
DEFAULT_INCLUDE_PATH (string) | |
PEAR_INSTALL_DIR (string) | |
PEAR_EXTENSION_DIR (string) | |
PHP_EXTENSION_DIR (string) | |
PHP_PREFIX (string) | |
PHP_BINDIR (string) | |
PHP_LIBDIR (string) | |
PHP_DATADIR (string) | |
PHP_SYSCONFDIR (string) | |
PHP_LOCALSTATEDIR (string) | |
PHP_CONFIG_FILE_PATH (string) | |
PHP_CONFIG_FILE_SCAN_DIR (string) | |
PHP_SHLIB_SUFFIX (string) | Available since PHP 4.3.0 |
PHP_OUTPUT_HANDLER_START (integer) | |
PHP_OUTPUT_HANDLER_CONT (integer) | |
PHP_OUTPUT_HANDLER_END (integer) | |
E_ERROR (integer) | |
E_WARNING (integer) | |
E_PARSE (integer) | |
E_NOTICE (integer) | |
E_CORE_ERROR (integer) | |
E_CORE_WARNING (integer) | |
E_COMPILE_ERROR (integer) | |
E_COMPILE_WARNING (integer) | |
E_USER_ERROR (integer) | |
E_USER_WARNING (integer) | |
E_USER_NOTICE (integer) | |
E_ALL (integer) | |
E_STRICT (integer) | Available since PHP 5.0.0 |
__COMPILER_HALT_OFFSET__ (integer) | Available since PHP 5.1.0 |
Constant |
---|
EXTR_OVERWRITE (integer) |
EXTR_SKIP (integer) |
EXTR_PREFIX_SAME (integer) |
EXTR_PREFIX_ALL (integer) |
EXTR_PREFIX_INVALID (integer) |
EXTR_PREFIX_IF_EXISTS (integer) |
EXTR_IF_EXISTS (integer) |
SORT_ASC (integer) |
SORT_DESC (integer) |
SORT_REGULAR (integer) |
SORT_NUMERIC (integer) |
SORT_STRING (integer) |
CASE_LOWER (integer) |
CASE_UPPER (integer) |
COUNT_NORMAL (integer) |
COUNT_RECURSIVE (integer) |
ASSERT_ACTIVE (integer) |
ASSERT_CALLBACK (integer) |
ASSERT_BAIL (integer) |
ASSERT_WARNING (integer) |
ASSERT_QUIET_EVAL (integer) |
CONNECTION_ABORTED (integer) |
CONNECTION_NORMAL (integer) |
CONNECTION_TIMEOUT (integer) |
INI_USER (integer) |
INI_PERDIR (integer) |
INI_SYSTEM (integer) |
INI_ALL (integer) |
M_E (float) |
M_LOG2E (float) |
M_LOG10E (float) |
M_LN2 (float) |
M_LN10 (float) |
M_PI (float) |
M_PI_2 (float) |
M_PI_4 (float) |
M_1_PI (float) |
M_2_PI (float) |
M_2_SQRTPI (float) |
M_SQRT2 (float) |
M_SQRT1_2 (float) |
CRYPT_SALT_LENGTH (integer) |
CRYPT_STD_DES (integer) |
CRYPT_EXT_DES (integer) |
CRYPT_MD5 (integer) |
CRYPT_BLOWFISH (integer) |
DIRECTORY_SEPARATOR (string) |
SEEK_SET (integer) |
SEEK_CUR (integer) |
SEEK_END (integer) |
LOCK_SH (integer) |
LOCK_EX (integer) |
LOCK_UN (integer) |
LOCK_NB (integer) |
HTML_SPECIALCHARS (integer) |
HTML_ENTITIES (integer) |
ENT_COMPAT (integer) |
ENT_QUOTES (integer) |
ENT_NOQUOTES (integer) |
INFO_GENERAL (integer) |
INFO_CREDITS (integer) |
INFO_CONFIGURATION (integer) |
INFO_MODULES (integer) |
INFO_ENVIRONMENT (integer) |
INFO_VARIABLES (integer) |
INFO_LICENSE (integer) |
INFO_ALL (integer) |
CREDITS_GROUP (integer) |
CREDITS_GENERAL (integer) |
CREDITS_SAPI (integer) |
CREDITS_MODULES (integer) |
CREDITS_DOCS (integer) |
CREDITS_FULLPAGE (integer) |
CREDITS_QA (integer) |
CREDITS_ALL (integer) |
STR_PAD_LEFT (integer) |
STR_PAD_RIGHT (integer) |
STR_PAD_BOTH (integer) |
PATHINFO_DIRNAME (integer) |
PATHINFO_BASENAME (integer) |
PATHINFO_EXTENSION (integer) |
PATH_SEPARATOR (string) |
CHAR_MAX (integer) |
LC_CTYPE (integer) |
LC_NUMERIC (integer) |
LC_TIME (integer) |
LC_COLLATE (integer) |
LC_MONETARY (integer) |
LC_ALL (integer) |
LC_MESSAGES (integer) |
ABDAY_1 (integer) |
ABDAY_2 (integer) |
ABDAY_3 (integer) |
ABDAY_4 (integer) |
ABDAY_5 (integer) |
ABDAY_6 (integer) |
ABDAY_7 (integer) |
DAY_1 (integer) |
DAY_2 (integer) |
DAY_3 (integer) |
DAY_4 (integer) |
DAY_5 (integer) |
DAY_6 (integer) |
DAY_7 (integer) |
ABMON_1 (integer) |
ABMON_2 (integer) |
ABMON_3 (integer) |
ABMON_4 (integer) |
ABMON_5 (integer) |
ABMON_6 (integer) |
ABMON_7 (integer) |
ABMON_8 (integer) |
ABMON_9 (integer) |
ABMON_10 (integer) |
ABMON_11 (integer) |
ABMON_12 (integer) |
MON_1 (integer) |
MON_2 (integer) |
MON_3 (integer) |
MON_4 (integer) |
MON_5 (integer) |
MON_6 (integer) |
MON_7 (integer) |
MON_8 (integer) |
MON_9 (integer) |
MON_10 (integer) |
MON_11 (integer) |
MON_12 (integer) |
AM_STR (integer) |
PM_STR (integer) |
D_T_FMT (integer) |
D_FMT (integer) |
T_FMT (integer) |
T_FMT_AMPM (integer) |
ERA (integer) |
ERA_YEAR (integer) |
ERA_D_T_FMT (integer) |
ERA_D_FMT (integer) |
ERA_T_FMT (integer) |
ALT_DIGITS (integer) |
INT_CURR_SYMBOL (integer) |
CURRENCY_SYMBOL (integer) |
CRNCYSTR (integer) |
MON_DECIMAL_POINT (integer) |
MON_THOUSANDS_SEP (integer) |
MON_GROUPING (integer) |
POSITIVE_SIGN (integer) |
NEGATIVE_SIGN (integer) |
INT_FRAC_DIGITS (integer) |
FRAC_DIGITS (integer) |
P_CS_PRECEDES (integer) |
P_SEP_BY_SPACE (integer) |
N_CS_PRECEDES (integer) |
N_SEP_BY_SPACE (integer) |
P_SIGN_POSN (integer) |
N_SIGN_POSN (integer) |
DECIMAL_POINT (integer) |
RADIXCHAR (integer) |
THOUSANDS_SEP (integer) |
THOUSEP (integer) |
GROUPING (integer) |
YESEXPR (integer) |
NOEXPR (integer) |
YESSTR (integer) |
NOSTR (integer) |
CODESET (integer) |
LOG_EMERG (integer) |
LOG_ALERT (integer) |
LOG_CRIT (integer) |
LOG_ERR (integer) |
LOG_WARNING (integer) |
LOG_NOTICE (integer) |
LOG_INFO (integer) |
LOG_DEBUG (integer) |
LOG_KERN (integer) |
LOG_USER (integer) |
LOG_MAIL (integer) |
LOG_DAEMON (integer) |
LOG_AUTH (integer) |
LOG_SYSLOG (integer) |
LOG_LPR (integer) |
LOG_NEWS (integer) |
LOG_UUCP (integer) |
LOG_CRON (integer) |
LOG_AUTHPRIV (integer) |
LOG_LOCAL0 (integer) |
LOG_LOCAL1 (integer) |
LOG_LOCAL2 (integer) |
LOG_LOCAL3 (integer) |
LOG_LOCAL4 (integer) |
LOG_LOCAL5 (integer) |
LOG_LOCAL6 (integer) |
LOG_LOCAL7 (integer) |
LOG_PID (integer) |
LOG_CONS (integer) |
LOG_ODELAY (integer) |
LOG_NDELAY (integer) |
LOG_NOWAIT (integer) |
LOG_PERROR (integer) |
Example | Name | Result |
---|---|---|
$a == $b | Equal | TRUE if $a is equal to $b. |
$a === $b | Identical | TRUE if $a is equal to $b, and they are of the same type. (introduced in PHP 4) |
$a != $b | Not equal | TRUE if $a is not equal to $b. |
$a <> $b | Not equal | TRUE if $a is not equal to $b. |
$a !== $b | Not identical | TRUE if $a is not equal to $b, or they are not of the same type. (introduced in PHP 4) |
$a < $b | Less than | TRUE if $a is strictly less than $b. |
$a > $b | Greater than | TRUE if $a is strictly greater than $b. |
$a <= $b | Less than or equal to | TRUE if $a is less than or equal to $b. |
$a >= $b | Greater than or equal to | TRUE if $a is greater than or equal to $b. |
Type of Operand 1 | Type of Operand 2 | Result |
---|---|---|
null or string | string | Convert NULL to "", numerical or lexical comparison |
bool or null | anything | Convert to bool, FALSE < TRUE |
object | object | Built-in classes can define its own comparison, different classes are uncomparable, same class - compare properties the same way as arrays (PHP 4), PHP 5 has its own explanation |
string, resource or number |
string, resource or number |
Translate strings and resources to numbers, usual math |
array | array | Array with fewer members is smaller, if key from operand 1 is not found in operand 2 then arrays are uncomparable, otherwise - compare value by value |
array | anything | array is always greater |
object | anything | object is always greater |
Expression | gettype() | empty() | is_null() | isset() | boolean : if($x) |
---|---|---|---|---|---|
$x == ""; | string | TRUE | FALSE | TRUE | FALSE |
$x == NULL; | NULL | TRUE | TRUE | FALSE | FALSE |
var $x; | NULL | TRUE | TRUE | FALSE | FALSE |
$x is undefined | NULL | TRUE | TRUE | FALSE | FALSE |
$x = array(); | array | TRUE | FALSE | TRUE | FALSE |
$x = false; | boolean | TRUE | FALSE | TRUE | FALSE |
$x = true; | boolean | FALSE | FALSE | TRUE | TRUE |
$x = 1; | integer | FALSE | FALSE | TRUE | TRUE |
$x = 42; | integer | FALSE | FALSE | TRUE | TRUE |
$x = 0; | integer | TRUE | FALSE | TRUE | FALSE |
$x = -1; | integer | FALSE | FALSE | TRUE | TRUE |
$x = "1" | string | FALSE | FALSE | TRUE | TRUE |
$x = "0" | string | TRUE | FALSE | TRUE | FALSE |
$x = "-1" | string | FALSE | FALSE | TRUE | TRUE |
$x = "php" | string | FALSE | FALSE | TRUE | TRUE |
$x = "true" | string | FALSE | FALSE | TRUE | TRUE |
$x = "false" | string | FALSE | FALSE | TRUE | TRUE |
TRUE | FALSE | 1 | 0 | -1 | "1" | "0" | "-1" | NULL | array() | "PHP" | |
---|---|---|---|---|---|---|---|---|---|---|---|
TRUE | TRUE | FALSE | TRUE | FALSE | TRUE | TRUE | FALSE | TRUE | FALSE | FALSE | TRUE |
FALSE | FALSE | TRUE | FALSE | TRUE | FALSE | FALSE | TRUE | FALSE | TRUE | TRUE | FALSE |
1 | TRUE | FALSE | TRUE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE |
0 | FALSE | TRUE | FALSE | TRUE | FALSE | FALSE | TRUE | FALSE | TRUE | FALSE | TRUE |
-1 | TRUE | FALSE | FALSE | FALSE | TRUE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE |
"1" | TRUE | FALSE | TRUE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE |
"0" | FALSE | TRUE | FALSE | TRUE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE |
"-1" | TRUE | FALSE | FALSE | FALSE | TRUE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE |
NULL | FALSE | TRUE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | TRUE | TRUE | FALSE |
array() | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | TRUE | TRUE | FALSE |
"PHP" | TRUE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | TRUE |
TRUE | FALSE | 1 | 0 | -1 | "1" | "0" | "-1" | NULL | array() | "PHP" | |
---|---|---|---|---|---|---|---|---|---|---|---|
TRUE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
1 | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
0 | FALSE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
-1 | FALSE | FALSE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
"1" | FALSE | FALSE | FALSE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE |
"0" | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE |
"-1" | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE |
NULL | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | TRUE | FALSE | FALSE |
array() | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | TRUE | FALSE |
"PHP" | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | TRUE |