|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-04-09 23:13 UTC] dphelan at bcps dot org
In PHP 4.1.2 (and 4.2.0-dev) Calling file() on a 4-line text file with Macintosh line endings (CR) results in a 1-element array: file: (file.txt) blah test three four Code: $array = file( 'file.txt. ); echo count( $array ); >> Returns '1' (Verified by print_r) file() is ignoring the line endings, but the correct result happens for files with Windows (CRLF) and Unix (LF) line endings. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 18:00:01 2025 UTC |
If you must use PHP < 4.3, you can do something like this: $fp = fopen($filename, "r"); $data = fread($fp, filesize($filename)); fclose($fp); $lines = explode("\r", $data); BEWARE: file() keeps the \r at the end of each line, whereas the code snippet above does not.