How to remove all redundant spaces from a string with Laravel

Categorized as Laravel Tagged

New minor version of Laravel Framework (9.7) has brought us a beautiful new string helper Str::squish. It removes all extra white spaces from a string, including between words. It’s like super-powered trim method.

$result = Str::squish('  Hello  I    love    you ');

// Hello I love you

Leave a reply

Your email address will not be published. Required fields are marked *