EncodingException example

static public function stringToUTF8Array($str$strictEncoding = true)
    {
        if ($str === "") {
            return array();
        }
        $ret = preg_split('//u', $str, -1, PREG_SPLIT_NO_EMPTY);
        if (preg_last_error() === PREG_BAD_UTF8_ERROR) {
            if (!$strictEncoding) {
                $str = mb_convert_encoding($str, 'UTF-8', 'UTF-8');
                $ret = self::stringToUTF8Array($str, false);
            } else {
                throw new EncodingException("String contains invalid UTF-8");
            }
        }
        return $ret;
    }
    
    /** * Converts an unicode code point to UTF-8 * * @param int $num Unicode code point * * @return string * * @codeCoverageIgnore */
Home | Imprint | This part of the site doesn't use cookies.