note 50297 added to function.fgets
| From: | purevel at hotmail dot com | Date: | Thu, 24 Feb 2005 04:57:56 +0000 |
| Subject: | note 50297 added to function.fgets | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85462@lists.php.net to get a copy of this message | ||
I couldn't find any code to read just a single, specified line of a file, so I wrote this.
<?php
function read_line($datafile,$linenum)
{
$file = fopen($datafile, 'r');
$i=1;
while ($i <= $linenum)
{
$line=""; $line = fgets($file);
$i++;
}
echo $line;
fclose($file);
}
?>
The only inputs required are the filename of the file being opened, and the line number.
For example using:
<?php
echo read_line('sample',2)
?>
will read the second line of the file "sample"
----
Manual Page -- http://www.php.net/manual/en/function.fgets.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50297
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50297&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50297&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50297&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50297&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50297&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50297&report=yes
Search -- http://master.php.net/manage/user-notes.php