trim_end
TABLE OF CONTENTS
Remove trailing characters from string
Definition
string trim_end(string $string, array[string] $charactersToRemove)
Removes $charactersToRemove from end of $string.
Parameters
string $string
The string to remove characters from.
array[string] $charactersToRemove
An array containing the characters to remove from the string.
If left empty, all whitespace characters are removed.
Returns
string
$string with the characters removed.
Examples
Transformation
{
a: trim_end('abcMyStringabc', ['a']),
b: trim_end('abcMyStringabc', ['a','b']),
c: trim_end('abcMyStringabc', ['a','b','c']),
d: trim_end('I have a string', ['']),
e: trim_end('I have a string', ['_']),
f: trim_end('No need to trim', []),
g: trim_end(null, [])
}Result
{
"a": "abcMyStringabc",
"b": "abcMyStringabc",
"c": "abcMyString",
"d": "_I have a string",
"e": "I have a string",
"f": "No need to trim",
"g": null
}Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article