mb_strtolower and utf8 strings

Simply put, define your own function which then calls mb_strtolower with mb_detect_encoding.

$results_array = array_map(function($var) {
      return mb_strtolower($var, mb_detect_encoding($var));
}, $results_array);

The solution is to tell mb_strtolower what your string encoding is:

echo mb_strtolower($str, 'UTF-8');

If you don't want to supply this parameter every time, set it once for all mb_ functions:

mb_internal_encoding('UTF-8');

Then you can call any mb_ function and it will handle your string as UTF-8:

echo mb_strtolower($str); // works without second parameter now

mb_detect_encoding happens to return 'UTF-8' because it detected it, but it is generally unreliable, since it's conceptually impossible to reliably detect arbitrarily encoded strings. Know what your strings are encoded in and pass this information explicitly.

Tags:

Php

Arrays