The following code is creating problem.
var_dump($name);
$name = mb_strtolower($name);
var_dump($name);
Output is
string(32) "brazil and techno开发者_Python百科logy, São Paulo"
string(32) "brazil and technology, s�o paulo"
Can someone please explain why I am getting an invalid character for ã? What am I doing wrong here?
mb_detect_encoding($name) says its UTF-8
mb_strtolower()
has a second parameter to specify the encoding. If omitted, it uses mb_internal_encoding()'s return value. Try adding that parameter explicitly. If you're on UTF-8:
$name = mb_strtolower($name, "UTF-8");
If that doesn't help, make 100% sure the incoming data is UTF-8 in all the steps along the way, and the output is UTF-8 as well. It could well be that you are working with IS-8859-1 data that gets garbled by the strtolower operation.
精彩评论