setEncoding($encoding, $convertEncoding); return $wrapper; } } throw new Exception\RuntimeException( 'No wrapper found supporting "' . $encoding . '"' . (($convertEncoding !== null) ? ' and "' . $convertEncoding . '"' : '') ); } /** * Get a list of all known single-byte character encodings * * @return string[] */ public static function getSingleByteEncodings() { return static::$singleByteEncodings; } /** * Check if a given encoding is a known single-byte character encoding * * @param string $encoding * @return bool */ public static function isSingleByteEncoding($encoding) { return in_array(strtoupper($encoding), static::$singleByteEncodings); } /** * Check if a given string is valid UTF-8 encoded * * @param string $str * @return bool */ public static function isValidUtf8($str) { return is_string($str) && ($str === '' || preg_match('/^./su', $str) == 1); } /** * Is PCRE compiled with Unicode support? * * @return bool */ public static function hasPcreUnicodeSupport() { if (static::$hasPcreUnicodeSupport === null) { ErrorHandler::start(); static::$hasPcreUnicodeSupport = defined('PREG_BAD_UTF8_OFFSET_ERROR') && preg_match('/\pL/u', 'a') == 1; ErrorHandler::stop(); } return static::$hasPcreUnicodeSupport; } }