Loading files/text.txt 0 → 100644 +2 −0 Original line number Diff line number Diff line Раз, два, три, четыре, Пять, шесть, семь, восемь. No newline at end of file index.php +19 −9 Original line number Diff line number Diff line <?php /** * Вернет кол-во дней между датами * @param DateTimeImmutable $dateStart дата начала * @param DateTimeImmutable $dateEnd дата окончания * @return int * Напиши функцию, которая принимает путь до файла, * проверяет, что файл существует и выводит пользователю весь контент файла * (файл можешь создать любой) * @param string $filePath путь до файла * @return void */ function diffDays(DateTimeImmutable $dateStart, DateTimeImmutable $dateEnd): int { $dateInterval = date_diff($dateStart, $dateEnd); return $dateInterval->format("%a") ; function readLogFile(string $filePath): void { if (file_exists($filePath)) { $text = ""; $file = fopen($filePath, "r"); while(!feof($file)) { $line = fgets($file); $text .= $line; } fclose($file); print($text); } else print("Такого файла не существует."); } ?> Loading @@ -21,7 +31,7 @@ function diffDays(DateTimeImmutable $dateStart, DateTimeImmutable $dateEnd): int </head> <body> <?php print(diffDays(new DateTimeImmutable(), new DateTimeImmutable("2025-01-01"))); readLogFile(__DIR__ . "/files/text.txt"); ?> </body> </html> No newline at end of file Loading
files/text.txt 0 → 100644 +2 −0 Original line number Diff line number Diff line Раз, два, три, четыре, Пять, шесть, семь, восемь. No newline at end of file
index.php +19 −9 Original line number Diff line number Diff line <?php /** * Вернет кол-во дней между датами * @param DateTimeImmutable $dateStart дата начала * @param DateTimeImmutable $dateEnd дата окончания * @return int * Напиши функцию, которая принимает путь до файла, * проверяет, что файл существует и выводит пользователю весь контент файла * (файл можешь создать любой) * @param string $filePath путь до файла * @return void */ function diffDays(DateTimeImmutable $dateStart, DateTimeImmutable $dateEnd): int { $dateInterval = date_diff($dateStart, $dateEnd); return $dateInterval->format("%a") ; function readLogFile(string $filePath): void { if (file_exists($filePath)) { $text = ""; $file = fopen($filePath, "r"); while(!feof($file)) { $line = fgets($file); $text .= $line; } fclose($file); print($text); } else print("Такого файла не существует."); } ?> Loading @@ -21,7 +31,7 @@ function diffDays(DateTimeImmutable $dateStart, DateTimeImmutable $dateEnd): int </head> <body> <?php print(diffDays(new DateTimeImmutable(), new DateTimeImmutable("2025-01-01"))); readLogFile(__DIR__ . "/files/text.txt"); ?> </body> </html> No newline at end of file