php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #14097 Add option to file() to strip \n
Submitted: 2001-11-17 21:52 UTC Modified: 2003-02-09 14:48 UTC
From: deelee at fundy dot net Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.6 OS: Linux
Private report: No CVE-ID: None
 [2001-11-17 21:52 UTC] deelee at fundy dot net
Using the file function, newlines (\n) are included in the read. The causes odd behaviour in other functions such as:

mail - If the subject parameter is loaded using the file function, the newline causes the headers sent using mail to be invalid. In the case of Eudora the header information is dispalyed in the message and the From field displays the server account that generated the message - in my case "WWW User".

array_search - All efforts to use this function fail with an array created with the file function. Only through the following cose will it produce the results expected:

$someArray = str_replace (array("\r", "\n"), '', $someArray);

(Thanks to Zak Greant for this code :)

in_array - Much like array_search, the results are misleading due to the presence of newlines. A match is never found even though an echo of the array being tested looks identical to the target string/integer.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-11-17 22:49 UTC] sniper@php.net
This is by design. Even the manual page for file() says it. :)

(Or was this a feature/change request to strip them?)

 [2001-11-18 05:03 UTC] deelee at fundy dot net
ID: 14097
Updated by: sniper
Reported By: deelee@fundy.net
Old Status: Open
Status: Bogus
Bug Type: Filesystem function related
Operating System: Linux
PHP Version: 4.0.6
New Comment:


This is by design. Even the manual page for file() says it. :)


(Or was this a feature/change request to strip them?)

Sniper,

In my humble opinion this is a bug as it causes other functions to perform irradically - array_search and in_array. At the very least there should be something in the docs for these functions to give a heads up. The ideal would be a change to the file function allowing the stripping of the newlines.

I guess this makes it a feature/change request.
 [2003-02-09 14:48 UTC] iliaa@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, 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/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.

PHP5-dev
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 02:01:31 2024 UTC