public static function check_encoding($data)
    {
        if (!is_array($data)) {
            return;
        }

        foreach ($data as $key => $value) {
            if (!is_array($value)) {
                // check if the multibyte library function is installed and use it.
                if (function_exists('mb_detect_encoding')) {
                    // check with mb library
                    if (is_string($key) && mb_detect_encoding($key, 'UTF-8', true) === false) {
                        throw new ClientException('Only UTF-8 encoded keys allowed. Wrong encoding in key string: ' . $key);
                    }
                    if (is_string($value) && mb_detect_encoding($value, 'UTF-8', true) === false) {
                        throw new ClientException('Only UTF-8 encoded values allowed. Wrong encoding in value string: ' . $value);
                    }
                } else {
                    // fallback to preg_match checking
                    if (is_string($key) && self::detect_utf($key) === false) {
                        throw new ClientException('Only UTF-8 encoded keys allowed. Wrong encoding in key string: ' . $key);
                    }
                    if (is_string($value) && self::detect_utf($value) === false) {
                        throw new ClientException('Only UTF-8 encoded values allowed. Wrong encoding in value string: ' . $value);
                    }
                }
            } else {
                self::check_encoding($value);
            }
        }
    }
public static function check_encoding($data)
    {
        if (!is_array($data)) {
            return;
        }

        foreach ($data as $key => $value) {
            if (!is_array($value)) {
                // check if the multibyte library function is installed and use it.
                if (function_exists('mb_detect_encoding')) {
                    // check with mb library
                    if (is_string($key) && mb_detect_encoding($key, 'UTF-8', true) === false) {
                        throw new ClientException('Only UTF-8 encoded keys allowed. Wrong encoding in key string: ' . $key);
                    }
                    if (is_string($value) && mb_detect_encoding($value, 'UTF-8', true) === false) {
                        throw new ClientException('Only UTF-8 encoded values allowed. Wrong encoding in value string: ' . $value);
                    }
                } else {
                    // fallback to preg_match checking
                    if (is_string($key) && self::detect_utf($key) === false) {
                        throw new ClientException('Only UTF-8 encoded keys allowed. Wrong encoding in key string: ' . $key);
                    }
                    if (is_string($value) && self::detect_utf($value) === false) {
                        throw new ClientException('Only UTF-8 encoded values allowed. Wrong encoding in value string: ' . $value);
                    }
                }
            } else {
                self::check_encoding($value);
            }
        }
    }
public static function check_encoding ( $ data ) { if ( ! is_array ( $ data ) ) { return ; } foreach ( $ data as $ key => $ value ) { if ( ! is_array ( $ value ) ) { // check if the multibyte library function is installed and use it. if ( function_exists ( 'mb_detect_encoding' ) ) { // check with mb library if ( is_string ( $ key ) && mb_detect_encoding ( $ key , 'UTF-8' , true ) === false ) { throw new ClientException ( 'Only UTF-8 encoded keys allowed. Wrong encoding in key string: ' . $ key ) ; } if ( is_string ( $ value ) && mb_detect_encoding ( $ value , 'UTF-8' , true ) === false ) { throw new ClientException ( 'Only UTF-8 encoded values allowed. Wrong encoding in value string: ' . $ value ) ; } } else { // fallback to preg_match checking if ( is_string ( $ key ) && self :: detect_utf ( $ key ) === false ) { throw new ClientException ( 'Only UTF-8 encoded keys allowed. Wrong encoding in key string: ' . $ key ) ; } if ( is_string ( $ value ) && self :: detect_utf ( $ value ) === false ) { throw new ClientException ( 'Only UTF-8 encoded values allowed. Wrong encoding in value string: ' . $ value ) ; } } } else { self :: check_encoding ( $ value ) ; } } }
This function checks that the encoding of the keys and
values of the array are utf-8, recursively.
It will raise an exception if it encounters wrong encoded strings.

@param array $data the data to check

@throws ClientException
This function checks that the encoding of the keys and values of the array are utf - 8 recursively . It will raise an exception if it encounters wrong encoded strings .