Skip to content

Commit cfa9827

Browse files
committed
add stripSpaces() method
1 parent 6f94b86 commit cfa9827

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use Flextype\Component\Strings;
2323

2424
| Method | Description |
2525
|---|---|
26+
| <a href="#strings_stripSpaces">`Strings::stripSpaces()`</a> | Strip all whitespaces from the given string. |
2627
| <a href="#strings_trimSlashes">`Strings::trimSlashes()`</a> | Removes any leading and trailing slashes from a string. |
2728
| <a href="#strings_reduceSlashes">`Strings::reduceSlashes()`</a> | Reduces multiple slashes in a string to single slashes. |
2829
| <a href="#strings_stripQuotes">`Strings::stripQuotes()`</a> | Removes single and double quotes from a string. |
@@ -60,6 +61,14 @@ use Flextype\Component\Strings;
6061

6162
<hr>
6263

64+
#### <a name="strings_stripSpaces"></a> Method: `Strings::stripSpaces()`
65+
66+
Strip all whitespaces from the given string.
67+
68+
```php
69+
$string = Strings::stripSpaces('SG-1 returns from an off-world mission');
70+
```
71+
6372
#### <a name="strings_trimSlashes"></a> Method: `Strings::trimSlashes()`
6473

6574
Removes any leading and trailing slashes from a string.

src/Strings.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,4 +518,14 @@ public static function padRight(string $string, int $length, string $pad = ' '):
518518
{
519519
return str_pad($string, $length, $pad, STR_PAD_RIGHT);
520520
}
521+
522+
/**
523+
* Strip all whitespaces from the given string.
524+
*
525+
* @param string $string The string to strip
526+
*/
527+
public static function stripSpaces(string $string): string
528+
{
529+
return preg_replace('/\s+/', '', $string);
530+
}
521531
}

0 commit comments

Comments
 (0)