Req #75977 [Opn]: Trim internal whitespace from string
| From: | jhdxr@php.net | Date: | Sun, 18 Feb 2018 09:25:49 +0000 |
| Subject: | Req #75977 [Opn]: Trim internal whitespace from string | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-214007@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75977&edit=1
ID: 75977
Updated by: jhdxr@php.net
Reported by: olafvdspek at gmail dot com
Summary: Trim internal whitespace from string
Status: Open
Type: Feature/Change Request
Package: Unknown/Other Function
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
what's the problem with
```
preg_replace('/\s+/', ' ', $str);
```
Previous Comments:
------------------------------------------------------------------------
[2018-02-18 08:50:23] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75977&edit=1