-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[10.x] Add new acronym method to Str for retrieving acronyms from strings #46615
Conversation
Would be awesome if you can determine the delimiter in the output, so you can have results like "L.i.f.e". |
… test case for this.
You can macro this into your own project. |
@taylorotwell I know I can, and I've done so in multiple projects. That's one of the reasons why I created this PR. While it's true that you can create your own macro for generating acronyms in your own Laravel project, adding this feature to the core |
@koenhendriks, I suggest you make this into a package in that case. |
@henzeb Seemed a bit overkill for such a small feature, but created it anyway. Should be live on packagist and can be used with
For future people landing here from search engines or github; If you want to use this functionality checkout https://github.com/koenhendriks/laravel-str-acronym |
Description
This Pull Request adds a new method to the
Str
helper class called acronym that retrieves an acronym consisting of the first letter of each word in a given string, concatenated without capitalization (other helper methods can be chained for this).The acronym method can be used in a variety of contexts, such as generating abbreviations for longer phrases or creating short identifiers from longer names.
Usage
To use the acronym method, simply call the method on the
Str
class and pass in a string as the argument:The acronym method splits the input string into words using spaces as a delimiter, retrieves the first letter of each word, and concatenates the resulting letters into a single string without capitalization.
An optional delimiter can be given which allows for more flexibility in how the resulting acronym is formatted.
Testing
This Pull Request includes a unit test for the acronym method to ensure that it works correctly and doesn't break any existing functionality.