$cur_encoding = mb_detect_encoding($in_str) ;
if($cur_encoding == "UTF-8" && mb_check_encoding($in_str,"UTF-8"))
return $in_str;
else
return utf8_encode($in_str);
First question:
I don't understand why we need use both functions here, mb_detect_encoding($in_str) and mb_check_encoding($in_str,"UTF-8")?
Which case will be caught by mb_detect_encoding($in_str) but not mb_check_encoding($in_str,"UTF-8") and vice versa?
Or will mb_check_encoding($in_str,"UT-8") catch all the
mb_detect_encoding($in_str) == "UTF-8", so we only need mb_check_encoding($in_str,"UT-8") ?
Second question:
If mb_check_encoding($in_str,"UT-8") works, why there are so many people trying to write their own codes to test if a string is utf-8 or not, if you see the posts below http://us2.php.net/manual/en/function.utf8-encode.php? That means mb_check_encoding($in_str,"UT-8") only works on some cases, what is this function's limit?
Third question:
Even with all the limits, still, this function applies on the data from databases created from same mysql dump file, should return the same results, but like in my case, it gives different results in my linux server (php5, mysql 4) and zend server (php5, mysql 5).