trim

Modified on Thu, 9 Jul at 10:50 AM

trim

TABLE OF CONTENTS

Remove leading and trailing characters from string

Definition

string trim(string $string, array[string] $charactersToRemove)

Removes $charactersToRemove from start and 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('abcMyStringabc', ['a']),
  b: trim('abcMyStringabc', ['a','b']),
  c: trim('abcMyStringabc', ['a','b','c']),
  d: trim('I have a string', ['']),
  e: trim('I have a string_', ['_']),
  f: trim('No need to trim', []),
  g: trim(null, [])
}
Result
{
  "a": "bcMyStringabc",
  "b": "cMyStringabc",
  "c": "MyString",
  "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

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article