filter icon indicating copy to clipboard operation
filter copied to clipboard

Common filters should use mb_* functions for string manipulation

Open lfbittencourt opened this issue 11 years ago • 2 comments

Hello,

Just a note here: upper, lower, capfirst and lowerfirst filters won't work with accented chars in words like "Luís Fernando". You should use mb_strtoupper, mb_strtolower and mb_convert_case functions to achieve the right behaviors.

If you like, I can submit a PR with some tests.

P.S.: how this package has so few stars?

lfbittencourt avatar Aug 05 '14 14:08 lfbittencourt

Thanks, feel free to submit a PR.

I just had a look - what would you do for lcfirst? A combination of mb_substr and mb_strtolower or is there a better way?

rmasters avatar Aug 09 '14 17:08 rmasters

Yeah, this combination wouldn't be bad:

function mb_lcfirst($value)
{
    return mb_strtoupper(mb_substr($value, 0, 1)) . mb_substr($value, 1);
}

BTW: after opening this issue, I've decided to create a "agnostic" filter engine that you can use along with any filter library (e.g. Zend Filter). This way it can offer a simple way to apply rules against concrete engines and return filtered data without implement any filter itself.

I would be happy if you visit the main project and the Laravel wrapper. There are no docs nor tests now, but the code is short and commented. Any help would be appreciated :-)

Oh, I'll make the PR anyway!

lfbittencourt avatar Aug 09 '14 22:08 lfbittencourt