public function convert_ascii($str)
{
$count = 1;
$out = '';
$temp = array();
for ($i = 0, $s = strlen($str); $i < $s; $i++) {
$ordinal = ord($str[$i]);
if ($ordinal < 128) {
$out .= $str[$i];
} else {
if (count($temp) === 0) {
$count = $ordinal < 224 ? 2 : 3;
}
$temp[] = $ordinal;
if (count($temp) === $count) {
$number = $count === 3 ? $temp[0] % 16 * 4096 + $temp[1] % 64 * 64 + $temp[2] % 64 : $temp[0] % 32 * 64 + $temp[1] % 64;
$out .= '&#' . $number . ';';
$count = 1;
$temp = array();
}
}
}
return $out;
}