Skip to content

Instantly share code, notes, and snippets.

@TyrfingMjolnir
Created March 18, 2014 09:52
Show Gist options
  • Save TyrfingMjolnir/9616923 to your computer and use it in GitHub Desktop.
Save TyrfingMjolnir/9616923 to your computer and use it in GitHub Desktop.
var $UTF8SpecialChars = array(
"|([\xC2-\xDF])([\x80-\xBF])|e",
"|(\xE0)([\xA0-\xBF])([\x80-\xBF])|e",
"|([\xE1-\xEF])([\x80-\xBF])([\x80-\xBF])|e",
"|(\xF0)([\x90-\xBF])([\x80-\xBF])([\x80-\xBF])|e",
"|([\xF1-\xF3])([\x80-\xBF])([\x80-\xBF])([\x80-\xBF])|e",
"|(\xF4)([\x80-\x8F])([\x80-\xBF])([\x80-\xBF])|e"
);
var $UTF8HTMLEntities = array(
"\$this->BuildExtendedChar('\\1','\\2')",
"\$this->BuildExtendedChar('\\1','\\2','\\3')",
"\$this->BuildExtendedChar('\\1','\\2','\\3')",
"\$this->BuildExtendedChar('\\1','\\2','\\3','\\4')",
"\$this->BuildExtendedChar('\\1','\\2','\\3','\\4')",
"\$this->BuildExtendedChar('\\1','\\2','\\3','\\4')"
);
function BuildExtendedChar( $byteOne, $byteTwo = "\x00", $byteThree = "\x00", $byteFour = "\x00" ) {
if( ord( $byteTwo ) >= 128 ) {
$tempChar = substr(decbin(ord($byteTwo)), -6);
if (ord($byteThree) >= 128) {
$tempChar .= substr(decbin(ord($byteThree)), -6);
if (ord($byteFour) >= 128) {
$tempChar .= substr(decbin(ord($byteFour)), -6);
$tempChar = substr(decbin(ord($byteOne)), -3) . $tempChar;
} else {
$tempChar = substr(decbin(ord($byteOne)), -4) . $tempChar;
}
} else {
$tempChar = substr(decbin(ord($byteOne)), -5) . $tempChar;
}
} else $tempChar = $byteOne;
$tempChar = '&#' . bindec($tempChar) . ';';
return $tempChar;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment