English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

Usage and examples of PHP preg_last_error() function

PHP Regular Expression (PCRE)

The preg_last_error function is used to return the error code of the last PCRE regular expression execution.

Syntax

int preg_last_error(void)

Online examples

<?php
preg_match('/(?:\D+|<\d+>)*[!?]/', 'foobar foobar foobar');
if (preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR) {
    print 'The backtrack limit was exhausted!';
}
?>

The execution result is as follows:

The backtrack limit was exhausted!

Return value

  • PREG_NO_ERROR
  • PREG_INTERNAL_ERROR
  • PREG_BACKTRACK_LIMIT_ERROR
  • PREG_RECURSION_LIMIT_ERROR
  • PREG_BAD_UTF8_ERROR
  • PREG_BAD_UTF8_OFFSET_ERROR

Detailed parameter descriptions can be viewed at:PHP Regular Expression (PCRE)

PHP Regular Expression (PCRE)