A practical guide to PHP's trim() function covering its signature, default behavior, and common use cases like cleaning form input, removing file line endings, and stripping path slashes. Key gotchas explained include: trim() only affects string edges (not the middle), it returns a new string rather than mutating the original, and its second argument is a character mask not an exact substring. Also covers Unicode whitespace limitations and the mb_trim() alternative introduced in PHP 8.4, plus comparisons with ltrim() and rtrim().

Sort: