Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

shaedrich
Copy link
Contributor

@shaedrich shaedrich commented Jul 21, 2025

Follow-up to #56338

Changes

  • Moved word splitting functionality to separate method
  • Add new method to Stringable as well
  • Add test for new method

Alternatives

  • adding mb_split_words() to helpers.php or a dedicated multi-byte.php

@rojtjo
Copy link
Contributor

rojtjo commented Jul 21, 2025

Would be nice if it could also handle punctuation, but I guess that might be a breaking change:

Str::splitWords('foo, bar, baz.') === ['foo', 'bar', 'baz'];

@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

@shaedrich
Copy link
Contributor Author

Str::splitWords('foo, bar, baz.')

That would be possible with this change:

-       return mb_split('\s+', $value);
+       return array_filter(mb_split('\W+', $value));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants