Files
oc-server3/htdocs/lib2/charset.inc.php
2013-08-01 12:14:46 +02:00

75 lines
2.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/****************************************************************************
For license information see doc/license.txt
Unicode Reminder メモ
charset related functions
****************************************************************************/
// replacement table for Unicode 0x100 to 0x1FF
$utf_xlatin = "A a A a A a C c C c C c C c D d D d E e E e E e E e E e G g G g " .
"G g G g H h H h I i I i I i I i I i IJijJ j K k K L l L l L l L " .
"l L l N n N n N n n n n O o O o Ö ö OEoeR r R r R r S s S s S s " .
"S s T t T t T t U u U u U u U u Ü ü U u W w Y y Y Z z Z z Z z ";
// replacement table for Unicode 0x2000 to 0x203F
$utf_punct = " ------|_'','\"\"\"\"++*>.... %%´\"\"`\"\"^<> !?- ";
// convert utf-8 string to iso-8859-1 and use replacemend characters if possible
function utf8ToIso88591($s)
{
global $utf_xlatin, $utf_punct;
$pos = 0;
$result = "";
while ($pos < strlen($s))
{
$c1 = ord($s[$pos++]);
if ($c1 < 0xC0)
$result .= chr($c1);
else if ($pos < strlen($s))
{
$c2 = ord($s[$pos++]);
if ($c1 < 0xE0)
{
$code = 0x40 * ($c1 & 0x1F) + ($c2 & 0x3F);
if ($code < 0x100)
$result .= chr($code);
else if ($code < 0x200)
{
$result .= $utf_xlatin[2*($code - 0x100)];
if ($utf_xlatin[2*($code - 0x100) + 1] != ' ')
$result .= $utf_xlatin[2*($code - 0x100) + 1];
}
else
$result .= "?";
}
else if ($pos < strlen($s))
{
$c3 = ord($s[$pos++]);
$code = 0x1000 * ($c1 & 0x0F) + 0x40 * ($c2 & 0x3F) + ($c3 & 0x3F);
switch ($code)
{
case 0x2026 : $result .= "..."; break;
case 0x2025 : $result .= ".."; break;
case 0x20AC : $result .= "Euro"; break;
case 0x2605 : $result .= "*"; break;
default:
if ($code >= 0x2000 && $code <= 0x203F)
$result .= $utf_punct[$code - 0x2000];
else
$result .= "?";
}
}
}
}
return $result;
}
?>