Skip to content

Instantly share code, notes, and snippets.

@juanparati
Created September 3, 2016 11:15
Show Gist options
  • Save juanparati/06fa5c68070ea00dbb92db04eb0e1cfa to your computer and use it in GitHub Desktop.
Save juanparati/06fa5c68070ea00dbb92db04eb0e1cfa to your computer and use it in GitHub Desktop.
function unicode2utf8($c)
{
$output="";
if($c < 0x80)
{
return chr($c);
}
else if($c < 0x800)
{
return chr( 0xc0 | ($c >> 6) ).chr( 0x80 | ($c & 0x3f) );
}
else if($c < 0x10000)
{
return chr( 0xe0 | ($c >> 12) ).chr( 0x80 | (($c >> 6) & 0x3f) ).chr( 0x80 | ($c & 0x3f) );
}
else if($c < 0x200000)
{
return chr(0xf0 | ($c >> 18)).chr(0x80 | (($c >> 12) & 0x3f)).chr(0x80 | (($c >> 6) & 0x3f)).chr(0x80 | ($c & 0x3f));
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment