function HTML_UTF16_UnEscape($HTML_text, $MSB_first) { $utf8_text = HTML_UTF8_UnEscape($HTML_text); return unicode_array_to_UTF16(UTF8_to_unicode_array($utf8_text), $MSB_first); }
function HTML_UTF8_Escape($UTF8_text) { // Ensure that the Unicode UTF8 encoding is valid. $UTF8_text = UTF8_fix($UTF8_text); // Change: changed to use smart_htmlspecialchars, so that characters which were already escaped would remain intact, as of revision 1.10 // Escape any special HTML characters present $UTF8_text = smart_htmlspecialchars($UTF8_text, ENT_QUOTES); // Convert the UTF-8 string to an array of unicode character numbers $unicode_array = UTF8_to_unicode_array($UTF8_text); // Create a string to receive the escaped HTML $htmloutput = ""; // Cycle through the unicode character numbers foreach ($unicode_array as $unichar) { // Check if the character needs to be escaped if ($unichar >= 0x0 && $unichar <= 0x7f) { // Character is less than 0x7F - add it to the html as is $htmloutput .= chr($unichar); } else { // Character is greater than 0x7F - escape it and add it to the html $htmloutput .= "&#x" . dechex($unichar) . ";"; } } // Return the resulting escaped HTML return $htmloutput; }