What is trim used for in php?
(PHP 4, PHP 5, PHP 7, PHP 8) Show trim — Strip whitespace (or other characters) from the beginning and end of a string Descriptiontrim(string
Parametersstring The string that will be trimmed. characters Optionally, the stripped characters can also be specified using the Return ValuesThe trimmed string. ExamplesExample #1 Usage example of trim()
= "\t\tThese are a few words :) ... "; The above example will output: string(32) " These are a few words :) ... " string(16) " Example string " string(11) "Hello World" string(28) "These are a few words :) ..." string(24) "These are a few words :)" string(5) "o Wor" string(9) "ello Worl" string(14) "Example string" Example #2 Trimming array values with trim()
The above example will output: array(3) { [0]=> string(5) "apple" [1]=> string(7) "banana " [2]=> string(11) " cranberry " } array(3) { [0]=> string(5) "apple" [1]=> string(6) "banana" [2]=> string(9) "cranberry" } Notes
See Also
There are no user contributed notes for this page. What is the use of trim in string?Overloads. Is trim a string method?The trim() method in Java String is a built-in function that eliminates leading and trailing spaces. The Unicode value of space character is '\u0020'. The trim() method in java checks this Unicode value before and after the string, if it exists then removes the spaces and returns the omitted string.
What is whitespace in PHP?More Detail. The ctype_space() function in PHP check for whitespace character(s). It returns TRUE if every character in text creates some sort of white space, FALSE otherwise. Besides the blank character this also includes tab, vertical tab, line feed, carriage return and form feed characters.
What is trim HTML?The trim() method removes whitespace from both sides of a string. The trim() method does not change the original string.
|