-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[8.x] Add Str::headline()
#39174
[8.x] Add Str::headline()
#39174
Conversation
Can't we simply use |
No unfortunately. It doesn’t split words in a string that are concatenated (with an uppercase letter signifying a new word), hyphenated, or underscored. You can take a look at the test cases for more examples 👍 |
Shouldn't |
I'm not sure what I have actually been using a custom function myself for a long time because I needed this functionality too: function to_title($value)
{
return ucwords(str_replace(['-', '_'], ' ', Str::kebab($value)));
} In fact, you can change 'laravel -_- php -_- framework ' which results in: 'Laravel Php Framework' |
This probably depends on what people interpret "title" as. I think title should be left in tact for developers whom do not want their strings split by casing differences in their string. For example: // "I Ran To Mr.McDonalds"
Str::title("I ran to Mr.McDonalds");
// "I Ran To Mr. Mc Donalds"
Str::studlyWords("I ran to Mr.McDonalds"); |
I don't mind the concept but maybe we can refine the method name? Any thoughts on Hard for me to come up with a method name that reflects what this does in a word or two. |
Yea absolutely! I don't mind Here's a couple ideas as well (let me know your thoughts):
|
Headline is cool. Memorable and fairly appropriate. |
Yeah |
Ok great -- let me update the PR with the name change. I'll comment back when it's ready 👍 |
Ok it's ready to go 👍 I've updated the logic to conform to use Let me know if you think this is okay, thanks! |
Description
This PR adds a new
Stringable
method to convert a string toStudly Words
.Purpose
studly()
but it concatenates words togethertitle()
, but it converts a series of words toucfirst
without separating words that are underscored, hyphenated, etc.Use Case
This is super useful for displaying "base-named" PHP classes to user interfaces as titles:
Or even taking slugs and converting them to a title:
Thanks for your time! No hard feelings on closure ❤️