- preg_match_all: documentation ( source)
- array_shift: documentation ( source)
- str_replace: documentation ( source)
- explode: documentation ( source)
- date: documentation ( source)
- strtotime: documentation ( source)
<?php
$filename = '{date:Ymd:-4 day}trac{date2:Ymd:-1 day}king{date:Ymd:-1 day}';
$modifiers = array();
preg_match_all('|\{([^\}]+)\}|', $filename, $modifiers);
foreach ($modifiers[1] as $id => $modifier) {
$args = explode(':', $modifier);
$method = array_shift($args);
if ($method == 'date' && count($args)) {
$replacement = count($args) == 2 ? date($args[0], strtotime($args[1])) : date($args[0]);
$filename = str_replace($modifiers[0][$id], $replacement, $filename);
}
}
echo $filename;