function addPercentToDateFormat($format) { $percent_format = ''; foreach (preg_split('//', $format, -1, PREG_SPLIT_NO_EMPTY) as $symbol) { if (ctype_alpha($symbol)) { $percent_format .= '%'; } $percent_format .= ( $symbol == 'i' ) ? 'M' : $symbol; } return $percent_format; }