Skip to content

Instantly share code, notes, and snippets.

From http://www.php.net/manual/en/function.chr.php#55978:
"I spent hours looking for a function which would take a numeric HTML entity value and output the appropriate UTF-8 bytes.
I found this at another site and only had to modify it slightly; so I don't take credit for this."
<?php function unichr($dec) {
if ($dec < 128) {
$utf = chr($dec);
} else if ($dec < 2048) {
$utf = chr(192 + (($dec - ($dec % 64)) / 64));