getTimeStamp(); foreach ($fil as $line) { $fields = array_filter(explode('|', $line)); if (count($fields) == 2) { // Date missing, insert $tuesday = strftime('%A, %d.%m.%Y ', strtotime('fourth tuesday of this month', $ts)); array_unshift($fields, $tuesday); } $ts=strtotime('+1 month', $ts); $li = implode('|', $fields); if ($li[0] != ' ') { $li = ' ' . $li; } if (substr($li, -1) != ' ') { $li = $li . ' '; } array_push($arr, '|' . $li . '|'); } file_put_contents($file_md, implode(PHP_EOL, $arr) . PHP_EOL); ?>