How to get ucfirst()
working with scandinavic characters?
$str = "SÄKYLÄ";
echo ucfirst(strtolower($str)); //prints SÄkylÄ
One possibility is use mb_convert_case()
but I'd like to know if this is possible using ucfirst()
$str = "SÄKYLÄ";
echo mb_convert_case($str, MB_CASE_TITLE, "UTF-8"); //prints Säkylä
Which function is faster for string capitalization?
Your problem here is not
ucfirst()
it'sstrtolower()
. You have to usemb_strtolower()
, to get your string in lower case, e.g.Also you can find a multibyte version of
ucfirst()
in the comments from the manual:Code from plemieux from the manual comment