Limit the return value of Str::limit to the given limit rather than n + strlen($end) #38535
Unanswered
MeesterDev
asked this question in
Ideas
Replies: 1 comment
-
I also agree. I think that current behavior is counterintuitive, especially since the documentation states: "The Str::limit method truncates the given string to the specified length". IIRC the current documentation should also reflect the fact that
and
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Str::limit('foobar', 3, '...');
results in "foo...". This is the same length as the the original string, and still 3 over the given limit.This way the function is not usable for limiting the length of a string that I want to store in a database. One might argue that you can use a lower limit, but I'd be limiting strings that do actually fit, as I've given a limit that's lower than the real limit.
My suggestion is to make
Str::limit('foobar', 5, '...')
return "fo..." instead of "fooba...". I do have doubts about how to handle cases where the limit is lower thanmb_strlen($end)
, but I guessStr:limit('foobar', 2, '...')
should return "..".I'd gladly make a PR for this. However, considering the edge case I mentioned and that, if I am nitpicking, it's a breaking change, I thought it best to suggest it as an idea first.
Beta Was this translation helpful? Give feedback.
All reactions