How to convert letter to utf-8 in html code (And -> &#1040)?

There is a base of symbols in the html code.
There is a need to compare the input character with the character code from the database.
How it can be implemented?
// This doesn't work as expected
echo htmlsprcialchars(htmlentity('A')); //And
July 9th 19 at 13:34
1 answer
July 9th 19 at 13:36
Solution
function encode($str) {
 $str = mb_convert_encoding($str , 'UTF-32', 'UTF-8');
 $split = str_split($str, 4);

 $res = "";
 foreach ($split as $c) {
 $cur = 0;
 for ($i = 0; $i < 4; $i++) {
 $cur |= ord($c[$i]) << (8*(3 - $i));
}
 $res .= "&#" . $cur . ";";
}
 return $res;
}

var_dump(encode('t'));

Find more questions by tags HTMLPHPUnicode