Search code examples
phpcharacter-encodingiconv

strtolower() providing faulty character?


I use strtolower() to convert strings to lower-case. When later in the code these strings are converted from UTF-8 to ANSI (Windows-1252) using iconv(), the function fails unless the //IGNORE statement is used.

I identified the offending character as the lower-case German Umlaut ü. However, prior to the ü being used, there is an upper-case Ü, which converts just fine. The difference is that the string containing the lower-case ü has been created using strtolower().

Why does strtolower() give me inconvertible results or wrong encoding? How can this be remedied?


Solution

  • Use mb_strtolower which supports multibyte chracters

    // Tell the function what charset you are using as second param. 
    echo mb_strtolower($str, 'UTF-8');