note 82404 deleted from ref.pcre by derick

From: Date: Mon, 14 Jul 2008 08:19:23 +0000
Subject: note 82404 deleted from ref.pcre by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-141466@lists.php.net to get a copy of this message
Note Submitter: Jonathan dot Daigle at example dot com ---- 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; } } ?>

« previous php.notes (#141466) next »