File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ use Flextype\Component\Strings;
3131| <a href =" #strings_validEncoding " >` Strings::validEncoding() ` </a > | Checks if the string is valid in UTF-8 encoding. |
3232| <a href =" #strings_fixEncoding " >` Strings::fixEncoding() ` </a > | Removes all invalid UTF-8 characters from a string. |
3333| <a href =" #strings_normalizeNewLines " >` Strings::normalizeNewLines() ` </a > | Standardize line endings to unix-like. |
34+ | <a href =" #strings_normalizeSpaces " >` Strings::normalizeSpaces() ` </a > | Normalize white-spaces to a single space. |
3435| <a href =" #strings_random " >` Strings::random() ` </a > | Creates a random string of characters. |
3536| <a href =" #strings_increment " >` Strings::increment() ` </a > | Add's ` _1 ` to a string or increment the ending number to allow ` _2 ` , ` _3 ` , etc. |
3637| <a href =" #strings_wordsCount " >` Strings::wordsCount() ` </a > | Return information about words used in a string. |
@@ -139,6 +140,14 @@ Standardize line endings to unix-like.
139140$string = Strings::normalizeNewLines('SG-1 returns from an off-world mission');
140141```
141142
143+ #### <a name =" strings_normalizeSpaces " ></a > Method: ` Strings::normalizeSpaces() `
144+
145+ Standardize line endings to unix-like.
146+
147+ ``` php
148+ $string = Strings::normalizeSpaces('SG-1 returns from an off-world mission');
149+ ```
150+
142151#### <a name =" strings_random " ></a > Method: ` Strings::random() `
143152
144153``` php
Original file line number Diff line number Diff line change @@ -129,6 +129,16 @@ public static function normalizeNewLines(string $string): string
129129 return str_replace (["\r\n" , "\r" ], "\n" , $ string );
130130 }
131131
132+ /**
133+ * Normalize white-spaces to a single space.
134+ *
135+ * @param string $string String
136+ */
137+ public static function normalizeSpaces (string $ string ): string
138+ {
139+ return preg_replace ('/\s+/ ' , ' ' , $ string );
140+ }
141+
132142 /**
133143 * Creates a random string of characters.
134144 *
You can’t perform that action at this time.
0 commit comments