Str.php
public static function encoding(string $str = null) : string
    {
        // If a string was given, we attempt to detect the encoding of the string if we are told to do so.
        // If we succeed, just return the determined type.
        if (true === static::$autoDetectEncoding && null !== $str && false !== $encoding = mb_detect_encoding($str)) {
            return $encoding;
        }

        // Otherwise let's return one of the defaults.
        return static::$encoding ?: 'utf-8';
    }
public static function encoding(string $str = null) : string
    {
        // If a string was given, we attempt to detect the encoding of the string if we are told to do so.
        // If we succeed, just return the determined type.
        if (true === static::$autoDetectEncoding && null !== $str && false !== $encoding = mb_detect_encoding($str)) {
            return $encoding;
        }

        // Otherwise let's return one of the defaults.
        return static::$encoding ?: 'utf-8';
    }
public static function encoding ( string $ str = null ) : string { // If a string was given, we attempt to detect the encoding of the string if we are told to do so. // If we succeed, just return the determined type. if ( true === static :: $ autoDetectEncoding && null !== $ str && false !== $ encoding = mb_detect_encoding ( $ str ) ) { return $ encoding ; } // Otherwise let's return one of the defaults. return static :: $ encoding ? : 'utf-8' ; }
Attempts to determine the encoding of a string if a string is given.

Upon failure or when no string is given, returns the static encoding set in this class or if that is not set,
the hardcoded default of 'utf-8'.

@param   string|null $str
@return  string
Attempts to determine the encoding of a string if a string is given .