note 99884 deleted from pcre.constants by danbrown
| From: | danbrown@php.net | Date: | Mon, 13 Sep 2010 17:48:51 +0000 |
| Subject: | note 99884 deleted from pcre.constants by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-172518@lists.php.net to get a copy of this message | ||
Note Submitter: Andrew
----
This is an edit to the note by Bastiaan.
I corrected the spelling of "decode" in the function name, and I removed references to
non-error constants, per the editor's note. I also changed all "print"s to
"return"s in line with more standard programming techniques.
<?php
function pcre_error_decode() {
switch (preg_last_error()) {
case PREG_NO_ERROR:
// do not print in this case
//return "Returned by preg_last_error() if there were no errors. Available since PHP
5.2.0.\n";
break;
case PREG_INTERNAL_ERROR:
return "Returned by preg_last_error() if there was an internal PCRE error. Available
since PHP 5.2.0.\n";
break;
case PREG_BACKTRACK_LIMIT_ERROR:
return "Returned by preg_last_error() if backtrack limit was exhausted. Available
since PHP 5.2.0.\n";
break;
case PREG_RECURSION_LIMIT_ERROR:
return "Returned by preg_last_error() if recursion limit was exhausted. Available
since PHP 5.2.0.\n";
break;
case PREG_BAD_UTF8_ERROR:
return "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.\n";
break;
case PREG_BAD_UTF8_OFFSET_ERROR:
return "Returned by preg_last_error() if the offset didn't correspond to the
begin of a valid UTF-8 code point (only when running a regex in UTF-8 mode). Available since PHP
5.3.0.\n";
break;
}
}
// Usage:
// Insert preg_* expression here
echo "PREG ERROR: ".pcre_error_decode();
?>