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

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP preg_last_error() Function Usage and Example

PHP Regular Expression (PCRE)

The preg_last_error function is used to return the error code generated by 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 'Backtrack limit was exhausted!';
}
?>

The execution result is as follows:

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

For detailed parameter descriptions, please refer to:PHP Regular Expression (PCRE)

PHP Regular Expression (PCRE)