note 47137 added to function.fgets
| From: | lelkesa at osu1 dot php dot net | Date: | Thu, 04 Nov 2004 10:54:04 +0000 |
| Subject: | note 47137 added to function.fgets | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-79592@lists.php.net to get a copy of this message | ||
Note that - afaik - fgets reads a line until it reaches a line feed (\\n). Carriage returns (\\r)
aren't processed as line endings.
However, nl2br insterts a <br /> tag before carriage returns as well.
This is useful (but not nice - I must admit) when you want to store a more lines in one.
<?php
function write_lines($text) {
$file = fopen('data.txt', 'a');
fwrite($file, str_replace("\n", ' ', $text)."\n");
fclose($file);
}
function read_all() {
$file = fopen('data.txt', 'r');
while (!feof($file)) {
$line = fgets($file);
echo '<u>Section</u><p>nl2br'.($line).'</p>';
}
fclose($file);
}
?>
Try it.
----
Manual Page -- http://www.php.net/manual/en/function.fgets.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47137
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47137&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47137&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47137&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47137&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47137&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47137&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47137&report=yes
Search -- http://master.php.net/manage/user-notes.php