php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48175 FILE_IGNORE_NEW_LINES does not remove "\r\n"
Submitted: 2009-05-07 09:23 UTC Modified: 2009-05-08 10:08 UTC
From: carsten_sttgt at gmx dot de Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 5.2.9 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: carsten_sttgt at gmx dot de
New email:
PHP Version: OS:

 

 [2009-05-07 09:23 UTC] carsten_sttgt at gmx dot de
Description:
------------
Hello,

if I use FILE_IGNORE_NEW_LINES with file(), a "\r\n" will not be removed. It works with a single "\r" or "\n".

(Tested on *nix and Windows.)

Regards,
Carsten


Reproduce code:
---------------
<?php
ini_set('auto_detect_line_endings', '1');
$f = tempnam('', 'php');

file_put_contents($f, "one\ntwo\n");
$a = file($f, FILE_IGNORE_NEW_LINES);
echo ord($a[0][strlen($a[0]) - 1]).PHP_EOL;

file_put_contents($f, "one\rtwo\r");
$a = file($f, FILE_IGNORE_NEW_LINES);
echo ord($a[0][strlen($a[0]) - 1]).PHP_EOL;

file_put_contents($f, "one\r\ntwo\r\n");
$a = file($f, FILE_IGNORE_NEW_LINES);
echo ord($a[0][strlen($a[0]) - 1]).PHP_EOL;

unlink($f);
?>


Expected result:
----------------
101
101
101


Actual result:
--------------
101
101
13


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-07 12:42 UTC] jani@php.net
See also bug #44034
 [2009-05-07 13:46 UTC] lbarnaud@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-05-07 14:48 UTC] carsten_sttgt at gmx dot de
executed with "php.exe -n test.php":

5.2.10-dev - Thu, 07 May 2009 11:42:06 +0100
101
101
13

5.3.0RC1 - Tue, 24 Mar 2009 22:33:04 +0000
5.3.0RC3-dev - Thu, 07 May 2009 13:08:08 +0000
101
101
101

6.0.0-dev - hu, 07 May 2009 11:30:12 +0000
13
101
101

So it's seems to be fixed in PHP5.3.

- is there a plan to release this PHP5.2.10 (have still the old behavior)?

- is this result expected in PHP6 (and why)?
 [2009-05-08 10:08 UTC] lbarnaud@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Fix merged to 5.2CVS and 6CVS
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jan 05 06:01:27 2025 UTC