php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #33790 Exec command trims spaces from output
Submitted: 2005-07-20 17:11 UTC Modified: 2005-08-04 10:54 UTC
From: marcus at names dot co dot uk Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5CVS, 4CVS (2005-07-20) OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: marcus at names dot co dot uk
New email:
PHP Version: OS:

 

 [2005-07-20 17:11 UTC] marcus at names dot co dot uk
Description:
------------
Each line in the output array returned as the second 
parameter of exec() is trimmed so that all white space 
is removed, rather than just new line characters. 

I found this issue while trying to use the following 
command to find all files in the current directory whose 
name ends in a space:

exec("find . -name '* '",$output_array,$status);

However, in $output_array the filenames have been 
trimmed so that they no longer end in a space.

Reproduce code:
---------------
exec("find . -name '* '",$output_array,$status);

Expected result:
----------------
array(
    "file1 "
    "file2 "
);

Actual result:
--------------
array(
    "file1"
    "file2"
);

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-20 17:13 UTC] marcus at names dot co dot uk
Description should read, "all white space 
is removed FROM THE END OF EACH LINE, rather than just 
new line characters".
 [2005-07-30 00:49 UTC] sniper@php.net
The manual should state this fact. There is no bug to fix as these functions have worked like this since PHP 3.

You can use ob_start()..passthru()..ob_get_contents() as workaround. Or you can use glob() or scandir() if you only need to get the filenames..

 [2005-08-01 10:35 UTC] marcus at names dot co dot uk
Hi. Thanks for reponding to this. However, just because 
a bug has existed for a long time doesn't mean it's not 
a bug. Removing new line characters is fine, but 
changing the actual output is just plain wrong!
 [2005-08-04 10:54 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"Trailing whitespace, such as \n, is not included in this array."
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC