Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
1 merge request!8Ptps function 8
......@@ -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
......@@ -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");
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment