#23636 [Bgs]: overriding auto_detect_line_endings

From: Date: Fri, 16 May 2003 04:23:19 +0000
Subject: #23636 [Bgs]: overriding auto_detect_line_endings
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-39758@lists.php.net to get a copy of this message
 ID:              23636
 User updated by: mitra at mitra dot biz
 Reported By:     mitra at mitra dot biz
 Status:          Bogus
 Bug Type:        Feature/Change Request
 PHP Version:     4.3.1
 New Comment:

Thanks - so maybe the docs should be updated to show that 
a) the settings are settable, the implication is that they can only be
set in php.ini 
b) the stream_get_line alternative to fgets 

Oops - since this is OpenSource documentation, maybe I should do it
...... done


Previous Comments:
------------------------------------------------------------------------

[2003-05-15 19:12:13] pollita@php.net

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, ":"); 

------------------------------------------------------------------------

[2003-05-15 02:21:39] mitra at mitra dot biz

I'm often running into problems with users, moving files around from a
Macintosh to Linux, it would be useful if PHP allowed modification of
auto_detect_line_endings in the php3, rather than just in php.ini. In
this way, files which handle user supplied files, can do the
auto-detection, while those reading files of known origin can leave it
as it is. 



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=23636&edit=1



Thread (6 messages)

« previous php.bugs (#39758) next »