trim_end

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

{
  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, [])
}
{
  "a": "abcMyStringabc",
  "b": "abcMyStringabc",
  "c": "abcMyString",
  "d": "_I have a string",
  "e": "I have a string",
  "f": "No need to trim",
  "g": null
}