I'm having to manually write:
if($pattern == 'REGEX_EMAIL') $pattern = REGEX_EMAIL;
if($pattern == 'REGEX_PASSWORD') $pattern = REGEX_PASSWORD;
Is there an other way?
I'm having to manually write:
if($pattern == 'REGEX_EMAIL') $pattern = REGEX_EMAIL;
if($pattern == 'REGEX_PASSWORD') $pattern = REGEX_PASSWORD;
Is there an other way?
You could use the constant
function to get the constant’s value by its name:
if (substr($pattern, 0, 6) == 'REGEX_' && defined($pattern)) {
$pattern = constant($pattern);
}
One solution (albeit ridiculous) would be to use an associative array...
$regexs = array('REGEX_NAME' => REGEX_NAME, 'REGEX_EMAIL' => REGEX_EMAIL);