Php mb_strtolower gives an invalid character

The following code creates a problem.

var_dump($name);
$name = mb_strtolower($name);
var_dump($name);

Output

string(32) "brazil and technology, São Paulo"
string(32) "brazil and technology, s o paulo"

Can someone explain why I get an invalid character for ã? What am I doing wrong here?

mb_detect_encoding($name) says its UTF-8
+3
source share
1 answer

mb_strtolower()has a second parameter to indicate the encoding. If this parameter is omitted, it uses the return value of mb_internal_encoding (). Try adding this parameter explicitly. If you are using UTF-8:

 $name = mb_strtolower($name, "UTF-8");

If this does not help, make sure that the input of UTF-8 is 100% sure that all steps are in this path, and the output is UTF-8. It is possible that you are working with IS-8859-1 data that is being distorted by the strtolower operation.

+8
source

Source: https://habr.com/ru/post/1762262/


All Articles