I've looked around a long time now, and all the alternatives and the mb_ functions are not working, any tips for why that might be? If you need any info on my servers part, I can provite that.
Asked
Active
Viewed 1,351 times
-2
-
got any code to share? – rackemup420 May 20 '17 at 17:58
-
Well, nothing that works. I've tried ucfirst, ucwords and so on, found some stackoverflow threads on mb_ucfirst, even user created functions, but nothing seems to work, so I don't have it right now. – Litenhundvilikkeinn May 20 '17 at 17:58
-
I want to make the string "æsomething" become "Æsomething" – Litenhundvilikkeinn May 20 '17 at 18:00
-
Siguza, I have tried that – Litenhundvilikkeinn May 20 '17 at 18:02
-
1@Litenhundvilikkeinn [and it works](https://3v4l.org/BeJNb). – Siguza May 20 '17 at 18:07
-
@siguza Does that have any requirements, like something I need to enable? – Litenhundvilikkeinn May 20 '17 at 18:13
-
@Litenhundvilikkeinn Well yes, [the `mb_*` functions](https://secure.php.net/manual/en/ref.mbstring.php). – Siguza May 20 '17 at 18:16
-
Thanks, that's what was missing! :) – Litenhundvilikkeinn May 20 '17 at 18:25
1 Answers
-1
This works (I know it does, I'm using it in my own projects)
function mb_ucfirst($string, $encoding='UTF-8') {
$firstChar = mb_substr($string, 0, 1, $encoding);
$then = mb_substr($string, 1, mb_strlen($string, $encoding)-1, $encoding);
return mb_strtoupper($firstChar, $encoding) . $then;
} // end function mb_ucfirst
Use it as mb_ucfirst($string);
Complete example:
<?php
$string = mb_ucfirst("ååååeee");
echo $string;
function mb_ucfirst($string, $encoding='UTF-8') {
$firstChar = mb_substr($string, 0, 1, $encoding);
$then = mb_substr($string, 1, mb_strlen($string, $encoding)-1, $encoding);
return mb_strtoupper($firstChar, $encoding) . $then;
} // end function mb_ucfirst
?>

junkfoodjunkie
- 3,168
- 1
- 19
- 33
-
Doesn't work, page just stays white when I use that. `$string = mb_ucfirst("ååååeee"); echo $string;` – Litenhundvilikkeinn May 20 '17 at 18:10
-
Then you have some other issue in the code. It's that simple. Check the logs. – junkfoodjunkie May 20 '17 at 18:12
-
-
Thanks, had to download php7.0-mbstring for my server and then it worked :) – Litenhundvilikkeinn May 20 '17 at 18:26