phpucfirst

Ucfirst doesnt work on non-english characters


I'm trying to make the first letter uppercase in a string. It works fine for english letters, but unfortunetely, it doesn't work on non-english chars, for example

echo ucfirst("çağla");

What is the correct way to make ucfirst work properly on all words including non-english chars ?


Solution

  • Thanks, I finally found this working function as Stony's suggestion.

    function myucfirst($str) {
        $fc = mb_strtoupper(mb_substr($str, 0, 1));
        return $fc.mb_substr($str, 1);
    }