php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #75977 Trim internal whitespace from string
Submitted: 2018-02-18 08:50 UTC Modified: 2018-02-19 12:08 UTC
Votes:2
Avg. Score:2.0 ± 1.0
Reproduced:1 of 2 (50.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: olafvdspek at gmail dot com Assigned:
Status: Suspended Package: Unknown/Other Function
PHP Version: Irrelevant 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: olafvdspek at gmail dot com
New email:
PHP Version: OS:

 

 [2018-02-18 08:50 UTC] olafvdspek at gmail dot com
Description:
------------
A function to trim / merge whitespace inside a string (so not just at the begin, end) would be nice to have and especially useful for single-line input.

It should replace all sequences of 1 or more whitespace characters by a single space.

Test script:
---------------
echo trim_all('A  B \t C \n D');

Expected result:
----------------
A B C D

Actual result:
--------------
A  B \t C
 D

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-18 09:25 UTC] jhdxr@php.net
what's the problem with
```
preg_replace('/\s+/', ' ', $str);
```
 [2018-02-18 13:22 UTC] olafvdspek at gmail dot com
Readability / teachability maybe. http://php.net/trim got a dedicated function / name as well..
 [2018-02-19 12:08 UTC] cmb@php.net
-Status: Open +Status: Suspended
 [2018-02-19 12:08 UTC] cmb@php.net
Adding yet another string function to ext/standard is certainly
not uncontroversial (at least I do not see sufficient benefit in
this case) – please, feel free to start the RFC process[1].  I'm
suspending this ticket for the time being.

[1] <https://wiki.php.net/rfc/howto>
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 12:01:29 2025 UTC