- substr: documentation ( source)
- chr: documentation ( source)
- mb_substr: documentation ( source)
- mb_strlen: documentation ( source)
- ord: documentation ( source)
<?php
function unicodeToHtmlEntities($string)
{
$result = '';
$length = mb_strlen($string);
for ($i = 0; $i < $length; $i++) {
$result .= '&#' . chr(mb_substr($string, $i, 1)) . ';';
}
return $result;
}
function unicodeToHtmlEntities2($string)
{
$result = '';
$length = strlen($string);
for ($i = 0; $i < $length; $i++) {
$result .= '&#' . ord(substr($string, $i, 1)) . ';';
}
return $result;
}
echo unicodeToHtmlEntities('йцук');