Skip to content
Advertisement

PHP function to adapt texte not working with special characters?

i’m struggling with a function that adapts a text depending of the first letter of a string.

JavaScript

OUTPUT: de élo �

EXPECTED OUTPUT: d’élo é

Basically, mb_strtolower should prevent all special characters to be miss-read. I tried different options, but i still get it wrong. I’d like the function to work with all accent types.

Any idea ?

Thanks a lot from France !

Advertisement

Answer

You need to set utf-8 encoding for the file. Try to put this at the top:

JavaScript

Then, instead of $str[0], use mb_substr($str, 0, 1)

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement