note 32090 added to function.fgets
| From: | mitra at path dot net | Date: | Fri, 16 May 2003 03:12:14 +0000 |
| Subject: | note 32090 added to function.fgets | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-48092@lists.php.net to get a copy of this message | ||
Pollard@php.net contributed this in response to a question on reading mac files ...
This option *IS* settable within your PHP scripts.
Example:
<?php
ini_set('auto_detect_line_endings', true);
$contents = file('unknowntype.txt');
ini_set('auto_detect_line_endings', false);
$content2 = file('unixfile.txt');
?>
Note, with PHP 4.3 anytime Mac files are read using fgets or file you'll need to
auto_detect_line_endings since \n is otherwise assumed. However, with PHP 5.0, stream_get_line()
will allow you to specify what line ending character to read up to.
\\ Read a line from a MAC file
stream_get_line($fp, 4096, "\r");
\\ Read a line from a UNIX file
stream_get_line($fp, 4096, "\n");
\\ Read a line from a DOS file
stream_get_line($fp, 4096, "\r\n");
\\ Read a line up to any filesystem line ending
ini_set('auto_detect_line_endings', true); fgets($fp);
\\ You can also make up your own line ending characters:
\\ Read up to the first instance of ":"
stream_get_line($fp, 4096, ":");
--
http://www.php.net/manual/en/function.fgets.php
http://master.php.net/manage/user-notes.php?action=edit+32090
http://master.php.net/manage/user-notes.php?action=delete+32090
http://master.php.net/manage/user-notes.php?action=reject+32090