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
69cf4ad1
Commit
69cf4ad1
authored
11 months ago
by
Адлан Шамавов
Browse files
Options
Downloads
Patches
Plain Diff
add readFileLineByLine
parent
42ee1495
No related branches found
Branches containing commit
No related tags found
1 merge request
!8
Ptps function 8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
index.php
+9
-10
9 additions, 10 deletions
index.php
with
9 additions
and
10 deletions
index.php
+
9
−
10
View file @
69cf4ad1
<?php
/**
*
Напиши функцию, которая принимает путь до файла,
*
проверяет, что файл существует и выводит пользователю весь контент файла
*
(файл можешь создать любой)
*
Переделай своё решение 8 задачи:
*
замени вывод всего текста из файла разом на
*
построчный вывод используя yield
* @param string $filePath путь до файла
* @return void
*/
function
read
Log
File
(
string
$filePath
):
void
{
function
readFil
eLineByLin
e
(
string
$filePath
):
iterable
{
if
(
file_exists
(
$filePath
))
{
$text
=
""
;
$file
=
fopen
(
$filePath
,
"r"
);
while
(
!
feof
(
$file
))
{
$line
=
fgets
(
$file
);
$text
.
=
$line
;
yield
fgets
(
$file
);
}
fclose
(
$file
);
print
(
$text
);
}
else
print
(
"Такого файла не существует."
)
;
else
yield
"Такого файла не существует."
;
}
?>
...
...
@@ -31,7 +28,9 @@ function readLogFile(string $filePath): void {
</head>
<body>
<?php
readLogFile
(
__DIR__
.
"/files/text.txt"
);
foreach
(
readFileLineByLine
(
__DIR__
.
"/files/text.txt"
)
as
$line
)
{
print
(
$line
);
}
?>
</body>
</html>
\ No newline at end of file
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