3 * koi8-r encoding functions
5 * takes a string of unicode entities and converts it to a koi8-r encoded string
6 * Unsupported characters are replaced with ?.
9 * @copyright Copyright © 2004-2005 The SquirrelMail Project Team
10 * @package squirrelmail
15 * Converts string to koi8-r
16 * @param string $string text with numeric unicode entities
17 * @return string koi8-r encoded text
19 function charset_encode_koi8_r ($string) {
20 // don't run encoding function, if there is no encoded characters
21 if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
23 $string=preg_replace("/&#([0-9]+);/e","unicodetokoi8r('\\1')",$string);
24 // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetokoi8r(hexdec('\\1'))",$string);
30 * Return koi8-r symbol when unicode character number is provided
32 * This function is used internally by charset_encode_koi8_r
33 * function. It might be unavailable to other squirrelmail functions.
34 * Don't use it or make sure, that functions/encode/koi8_r.php is
37 * @param int $var decimal unicode value
38 * @return string koi8-r character
40 function unicodetokoi8r($var) {
42 $koi8rchars=array('160' => "\x9A",
171 if (array_key_exists($var,$koi8rchars)) {
172 $ret=$koi8rchars[$var];