Skip to content

Instantly share code, notes, and snippets.

Created December 18, 2012 10:33
Show Gist options
  • Save anonymous/4326964 to your computer and use it in GitHub Desktop.
Save anonymous/4326964 to your computer and use it in GitHub Desktop.
Check for PREG errors after preg_* function call
switch( preg_last_error() ){
case PREG_NO_ERROR :
$preg_error = 'No error';
break;
case PREG_INTERNAL_ERROR :
$preg_error = 'An internal PCRE error';
break;
case PREG_BACKTRACK_LIMIT_ERROR :
$preg_error = 'Backtrack limit was exhausted';
break;
case PREG_RECURSION_LIMIT_ERROR :
$preg_error = 'Recursion limit was exhausted';
break;
case PREG_BAD_UTF8_ERROR :
$preg_error = 'Malformed UTF-8 data';
break;
case PREG_BAD_UTF8_OFFSET_ERROR :
$preg_error = 'Offset didn\'t correspond to the begin of a valid UTF-8 code point';
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment