trim()

Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published Aug 2, 2023
Contribute to Docs

The trim() function returns a string with whitespace stripped from the beginning and end of the string.

Syntax

trim($string, $characters)

Parameters:

  • $string: The string that will be trimmed.
  • $characters: Optionally, the stripped characters can be specified using the characters parameter. A range of characters can be specified with ... By default, it will strip:
    • Spaces " "
    • New lines \n
    • Carriage returns \r
    • Tabs \t
    • Vertical tabs \v
    • NULL characters \0

Codebyte Example

The following runnable example displays an array of strings before and after applying a function on each element. The function trims each element using the trim() function:

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?