xxxxxxxxxx
//If you try to use mb_detect_encoding to detect whether a string is valid UTF-8, use the strict mode, it is pretty worthless otherwise.
$str = 'áéóú'; // ISO-8859-1
mb_detect_encoding($str, 'UTF-8'); // 'UTF-8'
mb_detect_encoding($str, 'UTF-8', true); // false
//Example if you have a website that uses 2 different encoding and you want your values to be in utf8
$str = (mb_detect_encoding($str, 'UTF-8', true)) ? $str : utf8_encode($str);