Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tasks-php
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Адлан Шамавов
tasks-php
Commits
bad99227
Commit
bad99227
authored
11 months ago
by
Адлан Шамавов
Browse files
Options
Downloads
Patches
Plain Diff
fix
parent
369b5fed
No related branches found
Branches containing commit
No related tags found
1 merge request
!6
Ptps function 6
This commit is part of merge request
!6
. Comments created here will be created in the context of that merge request.
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
index.php
+0
-18
0 additions, 18 deletions
index.php
src/Functions.php
+0
-51
0 additions, 51 deletions
src/Functions.php
with
0 additions
and
69 deletions
index.php
+
0
−
18
Edit
View file @
bad99227
...
@@ -82,23 +82,5 @@ $func = new Hp\Test\Functions();
...
@@ -82,23 +82,5 @@ $func = new Hp\Test\Functions();
print
(
$date
->
format
(
"Y-m-d l"
)
.
"
\n
"
);
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"
);
?>
<h1>
Function 9
</h1>
<?php
foreach
(
$func
->
readFileLineByLine
(
__DIR__
.
"/public/text.txt"
)
as
$line
)
{
print
(
$line
);
}
?>
</body>
</body>
</html>
</html>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/Functions.php
+
0
−
51
Edit
View file @
bad99227
...
@@ -143,56 +143,5 @@ class Functions {
...
@@ -143,56 +143,5 @@ class Functions {
yield
new
DateTimeImmutable
(
$day
->
format
(
"Y-m-d"
));
yield
new
DateTimeImmutable
(
$day
->
format
(
"Y-m-d"
));
}
}
}
}
/**
* Вернет кол-во дней между датами
* @param DateTimeImmutable $dateStart дата начала
* @param DateTimeImmutable $dateEnd дата окончания
* @return int
*/
function
diffDays
(
DateTimeImmutable
$dateStart
,
DateTimeImmutable
$dateEnd
):
int
{
$dateInterval
=
date_diff
(
$dateStart
,
$dateEnd
);
return
$dateInterval
->
format
(
"%a"
)
;
}
/**
* Переделай своё решение 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
(
"Такого файла не существует."
);
}
/**
* Переделай своё решение 8 задачи:
* замени вывод всего текста из файла разом на
* построчный вывод используя yield
* @param string $filePath путь до файла
* @return void
*/
function
readFileLineByLine
(
string
$filePath
):
iterable
{
if
(
file_exists
(
$filePath
))
{
$file
=
fopen
(
$filePath
,
"r"
);
while
(
!
feof
(
$file
))
{
yield
fgets
(
$file
);
}
fclose
(
$file
);
}
else
yield
"Такого файла не существует."
;
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment