Skip to content
Snippets Groups Projects

Ptps function 9

Merged Адлан Шамавов requested to merge PTPS_Function_9 into main
1 unresolved thread
1 file
+ 22
27
Compare changes
  • Side-by-side
  • Inline
+ 22
27
<?php
require_once __DIR__ . '/vendor/autoload.php';
$func = new Hp\Test\Functions();
/**
* Переделай своё решение 8 задачи:
* замени вывод всего текста из файла разом на
* построчный вывод используя yield
* @param string $filePath путь до файла
* @return void
*/
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("Такого файла не существует.");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Function 1</h1>
@@ -77,21 +86,7 @@ $func = new Hp\Test\Functions();
<h1>Function 6</h1>
<?php
print("<h2>Пятницы 13: </h2>");
foreach($func->countFriday13(2024) as $date) {
print($date->format("Y-m-d l") . "\n");
}
?>
<h1>Function 7</h1>
<?php
print("<h2>Разница дней: </h2>");
print($func->diffDays(new DateTimeImmutable(), new DateTimeImmutable("2025-01-01")));
?>
<h1>Function 8</h1>
<?php
$func->readLogFile(__DIR__ . "/public/text.txt");
readLogFile(__DIR__ . "/files/text.txt");
?>
</body>
</html>
\ No newline at end of file
</html>
Loading