/** * This function returns a regex string of the format. * * @param $format The format name. * @param $regexes (Optional) Regexes replacements. * * @returns The regex string. * * @static */ function getRegex($format, $regexes = array()) { $s = '([0-5]{1}[0-9]{1}|[0-9]{1})'; // seconds and minutes $h = '([0-1]{1}[0-9]{1}|2[0-3]{1}|[0-9]{1})'; // hours $d = '([0-2]{1}[0-9]{1}|30|31|[0-9]{1})'; // day $m = '(0[0-9]{1}|1[0-2]{1}|[0-9]{1})'; // month $y = '([0-9]{4})'; // year 4 digits $t = '([\\-\\/\\.\\,\\: ])'; // separators $a = '([a-zA-Z]+)'; // alpha $w = '([0-9]+)'; // numbers // replace regexes if ($regexes) { foreach ($regexes as $k => $v) { ${$k} = $v; } } // format string $string = YDDateFormat::get($format, 'string'); // time representation $string = str_replace('%T', '%H:%M:%S', $string); // separators $string = preg_replace($t, $t, $string); // date $string = str_replace('%a', $a, $string); $string = str_replace('%A', $a, $string); $string = str_replace('%b', $a, $string); $string = str_replace('%B', $a, $string); $string = str_replace('%d', $d, $string); $string = str_replace('%m', $m, $string); $string = str_replace('%Y', $y, $string); $string = str_replace('%w', $w, $string); // time $string = str_replace('%H', $h, $string); $string = str_replace('%M', $s, $string); $string = str_replace('%S', $s, $string); return '/^' . $string . '$/i'; }