note 68371 deleted from function.unicode-encode by nlopess
| From: | nlopess@php.net | Date: | Thu, 25 Jan 2007 15:18:51 +0000 |
| Subject: | note 68371 deleted from function.unicode-encode by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-122194@lists.php.net to get a copy of this message | ||
Note Submitter: shidapu at mail dot ru
----
convert unicode string to any chatacter set
<?
function unicode_convert($str, $out_encoding)
{
$ret = '';
for($i=0; $i < strlen($str) / 2; $i++)
{
$dec = ord($str[$i*2])+256*ord($str[$i*2+1]);
if ($dec < 128)
{
$utf = chr($dec);
}
elseif ($dec < 2048)
{
$utf = chr(192 + (($dec - ($dec % 64)) / 64));
$utf .= chr(128 + ($dec % 64));
}
else
{
$utf = chr(224 + (($dec - ($dec % 4096)) / 4096));
$utf .= chr(128 + ((($dec % 4096) - ($dec % 64)) / 64));
$utf .= chr(128 + ($dec % 64));
}
$ret .= $utf;
}
$ret = iconv('utf-8', $out_encoding, $ret);
return $ret;
}
?>