note 19857 added to function.utf8-encode
| From: | lars at php2 dot chek dot com | Date: | Wed, 13 Mar 2002 13:29:10 +0000 |
| Subject: | note 19857 added to function.utf8-encode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-27717@lists.php.net to get a copy of this message | ||
This will also do the job for those who're interested:
<?
function utf8toiso8859($string)
{
$returns = "";
$UTF8len = array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 6);
$pos = 0;
$antal = strlen($string);
do
{
$c = ord($string[$pos]);
$len = $UTF8len[($c >> 2) & 0x3F];
switch ($len)
{
case 6:
$u = $c & 0x01;
break;
case 5:
$u = $c & 0x03;
break;
case 4:
$u = $c & 0x07;
break;
case 3:
$u = $c & 0x0F;
break;
case 2:
$u = $c & 0x1F;
break;
case 1:
$u = $c & 0x7F;
break;
case 0: /* unexpected start of a new character */
$u = $c & 0x3F;
$len = 5;
break;
}
while (--$len && (++$pos < $antal && $c =
ord($string[$pos])))
{
if (($c & 0xC0) == 0x80)
$u = ($u << 6) | ($c & 0x3F);
else
{ /* unexpected start of a new character */
$pos--;
break;
}
}
if ($u <= 0xFF)
$returns .= chr($u);
else
$returns .= '?';
} while (++$pos < $antal);
return $returns;
}
?>
--
http://www.php.net/manual/en/function.utf8-encode.php
http://master.php.net/manage/user-notes.php?action=edit+19857
http://master.php.net/manage/user-notes.php?action=delete+19857
http://master.php.net/manage/user-notes.php?action=reject+19857