|  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
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
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.
Block user comment
Status: Assign to:
Bug Type:
From: olafvdspek at gmail dot com
New email:
PHP Version: OS:


 [2018-02-18 08:50 UTC] olafvdspek at gmail dot com
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:

Actual result:
A  B \t C


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-18 09:25 UTC]
what's the problem with
preg_replace('/\s+/', ' ', $str);
 [2018-02-18 13:22 UTC] olafvdspek at gmail dot com
Readability / teachability maybe. got a dedicated function / name as well..
 [2018-02-19 12:08 UTC]
-Status: Open +Status: Suspended
 [2018-02-19 12:08 UTC]
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] <>
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Sep 28 10:03:42 2022 UTC