Commit 899adfa6 authored by Nikita Chernykh's avatar Nikita Chernykh
Browse files

Merge branch 'PTPS_Function_8' into 'main'

Ptps function 8

See merge request !8
parents 4555595f e932e694
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -101,5 +101,15 @@
        print "<h2>Разница дней: </h2>";
        print $func->diffDays(new DateTimeImmutable(), new DateTimeImmutable("2025-01-01"));
    ?>


    <h1>Function 8</h1>
    <?php
        try {
            $func->readLogFile(__DIR__ . "/public/text.txt");
        } catch (Exception $e) {
            print $e->getMessage();
        }
    ?>
</body>
</html>
 No newline at end of file
+26 −0
Original line number Diff line number Diff line
@@ -181,5 +181,31 @@ class Functions
        $dateInterval = date_diff($dateStart, $dateEnd);
        return (int)$dateInterval->format("%a") ;
    }

    /**
     * Напиши функцию, которая принимает путь до файла,
     * проверяет, что файл существует и выводит пользователю весь контент файла
     * (файл можешь создать любой)
     * @param string $filePath путь до файла
     * @return void
     * @throws Exception
     */

    public function readLogFile(string $filePath): void
    {
        if (file_exists($filePath)) {
            $text = "";
            $file = fopen($filePath, 'rb');
            while(!feof($file)) {
                $line = fgets($file);
                $text .= $line;
            }
            fclose($file);
            print $text;
        }
        else {
            throw new RuntimeException("File not found: $filePath");
        }
    }
}