trim

PHP 4, PHP 5, PHP 7, PHP 8
trim - Strip whitespace (or other characters) from the beginning and end of a string
Trim Online Tool
Manual
Code Examples

Example #1 Usage example of trim

Result: 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"
PHP Version:

Example #2 Trimming array values with trim

Result: 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" }
PHP Version:


Example #3 of trim

PHP Version:


Function trim:

Strings Functions

Most used PHP functions