Table of Contents

Syntax

int preg_last_error(void)

(PHP 5 >= 5.20)

RETURNS An error code indicating the last error that was generated by the regular expression.

Possible Return Values

PREG_NO_ERROR No error occurred.
PREG_INTERNAL_ERROR An internal regex error occurred.
PREG_BACKTRACK_LIMIT_ERROR The maximum number of backtracks was exceeded.
PREG_RECURSION_LIMIT_ERROR The maximum number of recursions was exceeded.
PREG_BAD_UTF8_ERROR The pattern contains bad character data that doesn't conform to the UTF-8 specification.

What it Does

When an error occurs executing a regular expression, this function will retrieve an error code indicating what the error was. The return value will be one of the constants listed above.

Example

// display the PCRE error that occurred
switch (preg_last_error()) {
  case PREG_NO_ERROR : echo 'No error'; break;
  case PREG_INTERNAL_ERROR : echo 'An internal PCRE error'; break;
  case PREG_BACKTRACK_LIMIT_ERROR : echo 'Backtrack limit exceeded'; break;
  case PREG_RECURSION_LIMIT_ERROR : echo 'Recursion limit exceeded'; break;
  case PREG_BAD_UTF8_ERROR : echo 'Bad UTF-8 error'; break;
}
 
preg_last_error.txt · Last modified: Apr 18, 2008 - 2:01pm (external edit)
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki