Difference between ucfirst() & Str::ucfirst()

Hello!
I’m new to Kirby since 2 months, but already love it! I came from modx and webflow, and beginner in php.
My question: why the php ucfirst() and the kirby Str::ucfirst() give not the same result?

<?= ucfirst('youHOU') ?> // YouHOU

it’s what I want and I think the normal result. But the Kirby method give

<?= Str::ucfirst('youHOU') ?> // Youhou

Is it normal?

That’s because Str::ucfirst() lowercases all but the first letter. also, it applies the utf8 safe versions mb_strtoupper($string ?? '', 'UTF-8'); and its lowercase equivalent the to uppercase/lowser those string parts.

OK so Str::ucfirst() is not only a UTF-8 safe version of ucfirst() as explain in Kirby doc, it has other goal.
I can’t use Str::ucfirst() for a text field where I want a sentence case and let other letters as it was entry.

Exactly.

If in doubt what a method does, you can jump to the source code easily from the documentation.

E.g. on the page Str::ucfirst() | Kirby CMS at the top of the page there is a link to the class method:

That leads you right to the source code:

Then from there you can jump to the methods used within that method.

1 Like