Created
September 22, 2020 19:09
-
-
Save fuzzyfox/4f2f2fc4b633c4f5e4ba0a5702f58492 to your computer and use it in GitHub Desktop.
Remove trailing whitespace from an input string (multiline).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function removeTrailingWhitespace(string $string) : string | |
{ | |
return preg_replace('/[ \t]+(\r?)$/m', '$1', $string); | |
} | |
// PHPUnit testcase for method | |
// public function testTestInternalRemoveTrailingWhitespace() | |
// { | |
// $this->assertSame( | |
// "\n some\r\n string\n\n\r\nto remove trailing\n whitespace from.\n\n", | |
// removeTrailingWhitespace("\n some \r\n string\n \n \r\nto remove trailing \n whitespace from. \n\n") | |
// ); | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment