For example:
$mystring = trim( " The free php sources ") ;
echo $mystring ;
echo $mystring ;
The free php sources //No whitespaces
What characters do Trim() strip ?
Trim function will strip the following characters:
- " " (ASCII 32 ): an ordinary space.
- "\t" (ASCII 9 ): a tab.
- "\n" (ASCII 10 ): a new line (line feed).
- "\r" (ASCII 13 ): a carriage return.
- "\0" (ASCII 0 ): the NUL-byte.
- "\x0B" (ASCII 11 ): a vertical tab.
Yes, this is possible and very easy, you just use a second parameter with all characters you want to stim.
Example: Trim these characters from the beginning and end of a string: "s" , "T" , "h".
$mystring = trim( "The free php sources" , "sTh") ;
echo $mystring ;
echo $mystring ;
e free php source
Trim from only the beginning or the end of a string:
To trim from the beginning, use ltrim() , and to trim from the end use rtrim()