public static function ensureUTF8($input)
    {
        $encoding = mb_detect_encoding($input, ['UTF-8', 'ISO-8859-1'], true);

        if ('ISO-8859-1' === $encoding) {
            return utf8_encode($input);
        } else {
            return $input;
        }
    }
public static function ensureUTF8($input)
    {
        $encoding = mb_detect_encoding($input, ['UTF-8', 'ISO-8859-1'], true);

        if ('ISO-8859-1' === $encoding) {
            return utf8_encode($input);
        } else {
            return $input;
        }
    }
public static function ensureUTF8 ( $ input ) { $ encoding = mb_detect_encoding ( $ input , [ 'UTF-8' , 'ISO-8859-1' ] , true ) ; if ( 'ISO-8859-1' === $ encoding ) { return utf8_encode ( $ input ) ; } else { return $ input ; } }
This method takes an input string, checks if it's not valid UTF-8 and
attempts to convert it to UTF-8 if it's not.

Note that currently this can only convert ISO-8859-1 to UTF-8 (latin-1),
anything else will likely fail.

@param string $input

@return string
This method takes an input string checks if it s not valid UTF - 8 and attempts to convert it to UTF - 8 if it s not .