The trim() function in PHP is an inbuilt function which removes whitespaces and also the predefined characters from both sides of a string that is left and right.
Parameters:The function accepts one mandatory parameter and one optional parameter as shown in the above syntax and described below.
- $string: This parameter specifies the string from which the whitespace and predefined characters from left and right are to be removed
- $charlist: This is an optional parameter which specifies the characters that are to be removed from the string. If this is not mentioned then all of the following characters will be removed:
- “\0” – NULL
- “\t” – tab
- “\n” – new line
- “\x0B” – vertical tab
- “\r” – carriage return
- ” ” – ordinary white space
Return Value: It returns the modified string by removing the whitespace and also the predefined characters from both sides of a string that is left and right.
Below programs illustrate the trim() function:
geeks for geeks
- p5.js | trim() function
- Node.js | trim() function
- How to trim all strings in an array in PHP ?
- How to get the function name inside a function in PHP ?
- D3.js | d3.hcl() Function
- p5.js | cos() function
- PHP | sin( ) Function
- PHP | Ds\Map first() Function
- p5.js | sq() function
- PHP | each() Function
- D3.js | d3.lab() Function
- p5.js | pow() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.