php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #23636 overriding auto_detect_line_endings
Submitted: 2003-05-15 02:21 UTC Modified: 2003-05-16 04:12 UTC
From: mitra at mitra dot biz Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.3.1 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mitra at mitra dot biz
New email:
PHP Version: OS:

 

 [2003-05-15 02:21 UTC] 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. 


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-15 19:12 UTC] 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 23:23 UTC] mitra at mitra dot biz
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
 [2003-05-16 01:48 UTC] philip@php.net
The documentation already shows it as being PHP_INI_ALL so why did you feel it implies otherwise?

http://www.php.net/manual/en/ref.filesystem.php
 [2003-05-16 03:29 UTC] mitra at mitra dot biz
How is one supposed to deduce that PHP_INI_ALL means you can change it with "ini_set", if one doesn't know that function exists. There is nothing on the ref.filesystem page, nor any link from PHP_INI_ALL to something that explains what it means. (not intending to be critical, but as someone whose done a lot of PHP programming, and was explicitly looking for a programatic way to set this variable, I couldn't find it).
 [2003-05-16 04:12 UTC] wez@php.net
It is worth noting that:
ini_set('auto_detect_line_endings', true);
is only inspected and used by the stream when it reads the *first* line (via fgets).  Subsequent reads use the value it detect then.
This is only an issue if (for some strange reason!) you have a mixture of different line ending conventions in a file.

In other words, the ini setting is only inspected at the time the stream is opened via fopen() or fsockopen().
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 17:01:33 2024 UTC