src/Koldy/Convert.php
public static function stringToUtf8(string $string): string
    {
        if (!mb_check_encoding($string, 'UTF-8') || !($string === mb_convert_encoding(mb_convert_encoding($string, 'UTF-32', 'UTF-8'), 'UTF-8', 'UTF-32'))) {

            $string = mb_convert_encoding($string, 'UTF-8');

            if (!mb_check_encoding($string, 'UTF-8')) {
                throw new ConvertException('Can not convert given string to UTF-8');
            }
        }

        return $string;
    }
public static function stringToUtf8(string $string): string
    {
        if (!mb_check_encoding($string, 'UTF-8') || !($string === mb_convert_encoding(mb_convert_encoding($string, 'UTF-32', 'UTF-8'), 'UTF-8', 'UTF-32'))) {

            $string = mb_convert_encoding($string, 'UTF-8');

            if (!mb_check_encoding($string, 'UTF-8')) {
                throw new ConvertException('Can not convert given string to UTF-8');
            }
        }

        return $string;
    }
public static function stringToUtf8 ( string $ string ) : string { if ( ! mb_check_encoding ( $ string , 'UTF-8' ) || ! ( $ string === mb_convert_encoding ( mb_convert_encoding ( $ string , 'UTF-32' , 'UTF-8' ) , 'UTF-8' , 'UTF-32' ) ) ) { $ string = mb_convert_encoding ( $ string , 'UTF-8' ) ; if ( ! mb_check_encoding ( $ string , 'UTF-8' ) ) { throw new ConvertException ( 'Can not convert given string to UTF-8' ) ; } } return $ string ; }
Convert given string into proper UTF-8 string

@param string $string

@return string
@throws ConvertException
@author Simon Brüchner (@powtac)

@link https://koldy.net/framework/docs/2.0/converters.md#stringtoutf8
@link http://php.net/manual/en/function.utf8-encode.php#102382
Convert given string into proper UTF - 8 string