switch($type) { case 'dt': if(preg_match('/^(\d\d\d\d)-(\d\d?)-(\d\d?)$/', $value, $m)) { return sprintf('%d-%02d-%02d', $m[1], $m[2], $m[3]); }