public static function processVariables($str) { if (!$str) { return ''; } $variables = ['MONTH', 'QUARTER', 'YEAR']; for ($i = 0; $i < count($variables); $i++) { $variable = $variables[$i]; $regExp = '/:' . $variable . '[+-]?[\\d]*/'; preg_match_all($regExp, $str, $matches); $matches = $matches[0]; if (count($matches) == 0) { continue; } usort($matches, function ($a, $b) { return strlen($b) - strlen($a); }); foreach ($matches as $match) { $offset = 0; $addArray = explode('+', $match); $minArray = explode('-', $match); if (count($addArray) > 1) { $offset = intval($addArray[1]); } elseif (count($minArray) > 1) { $offset = intval($minArray[1]) * -1; } $val = Utils::getDatePart($variable, $offset); $str = str_replace($match, $val, $str); } } return $str; }