1) || /* multi-byte [unicode] */ ($o < 32 || $o > 126) || /* <- control / latin weirdos -> */ ($o > 33 && $o < 40) || /* quotes + ampersand */ ($o > 59 && $o < 63) /* html */ ) { // convert to numeric entity $c = mb_encode_numericentity($c, array(0x0, 0xffff, 0, 0xffff), 'UTF-8'); if ($allow_html) { if ($c == '<') $c = '<'; if ($c == '>') $c = '>'; if ($c == '=') $c = '='; if ($c == '"') $c = '"'; if ($c == ''') $c = '\''; if ($c == '&') $c = '&'; // DM 24.08.2016 Re-added because OIDplus 1.0 XML export } if (!$encode_linebreaks) { if ($allow_html) { if ($c == " ") $c = "
"; if ($c == " ") $c = "
"; } else { if ($c == " ") $c = "\n"; if ($c == " ") $c = "\r"; } } } $str2 .= $c; } return $str2; } function ordUTF8($c, $index = 0, &$bytes = null) { // http://de.php.net/manual/en/function.ord.php#78032 $len = strlen($c); $bytes = 0; if ($index >= $len) { return false; } $h = ord($c[$index]); if ($h <= 0x7F) { $bytes = 1; return $h; } else if ($h < 0xC2) { return false; } else if ($h <= 0xDF && $index < $len - 1) { $bytes = 2; return ($h & 0x1F) << 6 | (ord($c[$index + 1]) & 0x3F); } else if ($h <= 0xEF && $index < $len - 2) { $bytes = 3; return ($h & 0x0F) << 12 | (ord($c[$index + 1]) & 0x3F) << 6 | (ord($c[$index + 2]) & 0x3F); } else if ($h <= 0xF4 && $index < $len - 3) { $bytes = 4; return ($h & 0x0F) << 18 | (ord($c[$index + 1]) & 0x3F) << 12 | (ord($c[$index + 2]) & 0x3F) << 6 | (ord($c[$index + 3]) & 0x3F); } else { return false; } } function utf16_to_utf8($str) { // http://betamode.de/2008/09/08/php-utf-16-zu-utf-8-konvertieren/ // http://www.moddular.org/log/utf16-to-utf8 $c0 = ord($str[0]); $c1 = ord($str[1]); if ($c0 == 0xFE && $c1 == 0xFF) { $be = true; } else if ($c0 == 0xFF && $c1 == 0xFE) { $be = false; } else { return $str; } $str = substr($str, 2); $len = strlen($str); $dec = ''; for ($i = 0; $i < $len; $i += 2) { $c = ($be) ? ord($str[$i]) << 8 | ord($str[$i + 1]) : ord($str[$i + 1]) << 8 | ord($str[$i]); if ($c >= 0x0001 && $c <= 0x007F) { $dec .= chr($c); } else if ($c > 0x07FF) { $dec .= chr(0xE0 | (($c >> 12) & 0x0F)); $dec .= chr(0x80 | (($c >> 6) & 0x3F)); $dec .= chr(0x80 | (($c >> 0) & 0x3F)); } else { $dec .= chr(0xC0 | (($c >> 6) & 0x1F)); $dec .= chr(0x80 | (($c >> 0) & 0x3F)); } } return $dec; } function html_named_to_numeric_entities($str) { $str = mb_convert_encoding($str, 'UTF-8'); return mb_htmlentities(decodeNamedEntities($str)); } if (!function_exists('decodeNamedEntities')) { function decodeNamedEntities($string) { // https://stackoverflow.com/questions/20406599/how-to-encode-for-entity-igrave-not-defined-error-in-xml-feed static $entities = NULL; if (NULL === $entities) { $entities = array_flip( array_diff( get_html_translation_table(HTML_ENTITIES, ENT_COMPAT | ENT_HTML401, 'UTF-8'), get_html_translation_table(HTML_ENTITIES, ENT_COMPAT | ENT_XML1, 'UTF-8') ) ); } return str_replace(array_keys($entities), $entities, $string); } } if (!function_exists('mb_convert_encoding')) { // https://riptutorial.com/php/example/15633/converting-unicode-characters-to-their-numeric-value-and-or-html-entities-using-php function mb_convert_encoding($str, $to_encoding, $from_encoding = NULL) { return iconv(($from_encoding === NULL) ? mb_internal_encoding() : $from_encoding, $to_encoding, $str); } } if (!function_exists('mb_ord')) { // https://riptutorial.com/php/example/15633/converting-unicode-characters-to-their-numeric-value-and-or-html-entities-using-php function mb_ord($char, $encoding = 'UTF-8') { if ($encoding === 'UCS-4BE') { list(, $ord) = (strlen($char) === 4) ? @unpack('N', $char) : @unpack('n', $char); return $ord; } else { return mb_ord(mb_convert_encoding($char, 'UCS-4BE', $encoding), 'UCS-4BE'); } } } if (!function_exists('mb_htmlentities')) { // https://riptutorial.com/php/example/15633/converting-unicode-characters-to-their-numeric-value-and-or-html-entities-using-php // modified function mb_htmlentities($string, $hex = true, $encoding = 'UTF-8') { return preg_replace_callback('/[\x{80}-\x{10FFFF}]/u', function ($match) use ($hex, $encoding) { $ord = (strtoupper($encoding) == 'UTF-8') ? ordUTF8($match[0]) : mb_ord($match[0]); return sprintf($hex ? '&#x%X;' : '&#%d;', $ord); }, $string); } }