PHP trim()
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 NULLcharacters\0
- Spaces
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:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.