-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[9.x] Add String::squish() helper #41791
Conversation
Looks like that failing build may not be my fault 🤞 |
You can try force-pushing your branch to re-trigger GitHub Actions and get all-green. A recent merged PR can cause |
Can you also add it to fluent strings? |
Of course, added to |
@dwightwatson could the replacement param be passed as second argument like this: public static function squish($value, $replacement = ' ')
{
return preg_replace('/\s+/', $replacement, trim($value));
} |
* Add squish helper * Additional test case * Add squish to Stringable * Fix code formatting * Make more consistent * formatting Co-authored-by: Taylor Otwell <[email protected]>
This proposes a new string helper method called
squish
, which is named similarly to the one in Rails. I know there's a lot of fair scrutiny given to adding new helpers but felt it was worth putting it out there in case you saw the usefulness that I do.My use-cases are both when outputting user input that had additional unnecessary whitespace, and also when creating interpolated strings that have optional values (i.e.
"A {$description} listing has been created."
). In both of these instances usingsquish
would make the content appear more professional.If you do like this addition I can follow-up and add it to
Stringable
as well.