note 110194 added to function.preg-last-error
| From: | falidelu | Date: | Fri, 28 Sep 2012 18:06:10 +0000 |
| Subject: | note 110194 added to function.preg-last-error | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-191066@lists.php.net to get a copy of this message | ||
Return values of int preg_last_error():
0 === PREG_NO_ERROR
1 === PREG_INTERNAL_ERROR
2 === PREG_BACKTRACK_LIMIT_ERROR
3 === PREG_RECURSION_LIMIT_ERROR
4 === PREG_BAD_UTF8_ERROR
5 === PREG_BAD_UTF8_OFFSET_ERROR
Trick: PHP manual says constants allow only scalar values... like strings... and PHP manual also
says that strings "behave" like (not are) array of characters.
<?php
// build constant error_code_array as constant string concatenation of
"ValueReturnedByFunctionAsErrorCode#WhateverExplanationString##"
$str = "0#PREG_NO_ERROR##";
$str .= "1#PREG_INTERNAL_ERROR##";
$str .= "2#PREG_BACKTRACK_LIMIT_ERROR##";
$str .= "3#PREG_RECURSION_LIMIT_ERROR##";
$str .= "4#PREG_BAD_UTF8_ERROR##";
$str .= "5#PREG_BAD_UTF8_OFFSET_ERROR##" ;
define( "const_preg_last_error", $str );
// wordwrap...
function preg_last_error_string()
{
return strstr( strstr( const_preg_last_error , preg_last_error()."#" ) , "##",
TRUE);
// strstr( $arg1, $arg2, TRUE ) requires PHP >= 5.3.0
return mb_strstr( mb_strstr( const_preg_last_error , preg_last_error()."#" ) ,
"##", TRUE);
// mb_strstr() requires PHP >= 5.2.0
$idx_begin = strpos( const_preg_last_error , preg_last_error()."#");
$idx_end = strpos( const_preg_last_error , "##", $idx_begin);
return substr( const_preg_last_error , $idx_begin, ($idx_end - $idx_begin) ) ;
// strpos and substr are PHP 4
}
echo preg_last_error_string() ;
?>
----
Server IP: 69.147.83.199
Probable Submitter: 79.145.228.16
----
Manual Page -- http://www.php.net/manual/en/function.preg-last-error.php
Edit -- https://master.php.net/note/edit/110194
Del: integrated -- https://master.php.net/note/delete/110194/integrated
Del: useless -- https://master.php.net/note/delete/110194/useless
Del: bad code -- https://master.php.net/note/delete/110194/bad+code
Del: spam -- https://master.php.net/note/delete/110194/spam
Del: non-english -- https://master.php.net/note/delete/110194/non-english
Del: in docs -- https://master.php.net/note/delete/110194/in+docs
Del: other reasons-- https://master.php.net/note/delete/110194
Reject -- https://master.php.net/note/reject/110194
Search -- https://master.php.net/manage/user-notes.php