note 82404 added to ref.pcre
| From: | Jonathan dot Daigle at example dot com | Date: | Wed, 09 Apr 2008 14:39:40 +0000 |
| Subject: | note 82404 added to ref.pcre | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-138064@lists.php.net to get a copy of this message | ||
In answer to "me at codingbear.com"
You can achieve the same result in a way that at my sense is easier.
However, If you have a custom error handler already set $php_errormsg wont be populated and you will
have to retreive your last error from your custom error handler.
<?php
/**
* The RegEx validation class .
*
* Usage:
* if (!RegEx::isValid($expression)) {
* echo 'Your regular expression is invalid because: ' . RegEx::error();
* }
*/
class RegEx {
/**
* Validates a regular expression. Returns TRUE
* if the expression is valid, FALSE if not. If
* the expression is not valid, the reason why
* can be fetched from RegEx::error().
*
* @access public
* @static
* @param string $regex Regular Expression
* @return bool
*/
function isValid($regex)
{
self::error(FALSE);
$nbMatch = FALSE;
$nbMatch = @preg_match($regex, '');
if($nbMatch === FALSE){
self::error(substr($php_errormsg, 14));
return FALSE;
}
return TRUE;
}
/**
* Holds the error from the last validation check.
*
* The first parameter is used internally and should
* not be used by the developer.
*
* @access public
* @static
* @param FALSE|string $value value to set for $flag
* @return FALSE|string
*/
function error($value = NULL)
{
static $flag = FALSE;
if (!is_null($value))
{
$flag = $value;
}
return $flag;
}
}
?>
----
Server IP: 66.207.199.35
Probable Submitter: 74.13.246.234
----
Manual Page -- http://www.php.net/manual/en/ref.pcre.php
Edit -- https://master.php.net/note/edit/82404
Del: integrated -- https://master.php.net/note/delete/82404/integrated
Del: useless -- https://master.php.net/note/delete/82404/useless
Del: bad code -- https://master.php.net/note/delete/82404/bad+code
Del: spam -- https://master.php.net/note/delete/82404/spam
Del: non-english -- https://master.php.net/note/delete/82404/non-english
Del: in docs -- https://master.php.net/note/delete/82404/in+docs
Del: other reasons-- https://master.php.net/note/delete/82404
Reject -- https://master.php.net/note/reject/82404
Search -- https://master.php.net/manage/user-notes.php