| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * iso-8859-7 encoding functions |
| 5 | * |
| 6 | * takes a string of unicode entities and converts it to a iso-8859-7 encoded string |
| 7 | * Unsupported characters are replaced with ?. |
| 8 | * |
| 9 | * @copyright 2004-2009 The SquirrelMail Project Team |
| 10 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
| 11 | * @version $Id$ |
| 12 | * @package squirrelmail |
| 13 | * @subpackage encode |
| 14 | */ |
| 15 | |
| 16 | /** |
| 17 | * Converts string to iso-8859-7 |
| 18 | * @param string $string text with numeric unicode entities |
| 19 | * @return string iso-8859-7 encoded text |
| 20 | */ |
| 21 | function charset_encode_iso_8859_7 ($string) { |
| 22 | // don't run encoding function, if there is no encoded characters |
| 23 | if (! preg_match("'&#[0-9]+;'",$string) ) return $string; |
| 24 | |
| 25 | $string=preg_replace("/&#([0-9]+);/e","unicodetoiso88597('\\1')",$string); |
| 26 | // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetoiso88597(hexdec('\\1'))",$string); |
| 27 | |
| 28 | return $string; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Return iso-8859-7 symbol when unicode character number is provided |
| 33 | * |
| 34 | * This function is used internally by charset_encode_iso_8859_7 |
| 35 | * function. It might be unavailable to other SquirrelMail functions. |
| 36 | * Don't use it or make sure, that functions/encode/iso_8859_7.php is |
| 37 | * included. |
| 38 | * |
| 39 | * @param int $var decimal unicode value |
| 40 | * @return string iso-8859-7 character |
| 41 | */ |
| 42 | function unicodetoiso88597($var) { |
| 43 | |
| 44 | $iso88597chars=array('160' => "\xA0", |
| 45 | '163' => "\xA3", |
| 46 | '166' => "\xA6", |
| 47 | '167' => "\xA7", |
| 48 | '168' => "\xA8", |
| 49 | '169' => "\xA9", |
| 50 | '171' => "\xAB", |
| 51 | '172' => "\xAC", |
| 52 | '173' => "\xAD", |
| 53 | '176' => "\xB0", |
| 54 | '177' => "\xB1", |
| 55 | '178' => "\xB2", |
| 56 | '179' => "\xB3", |
| 57 | '183' => "\xB7", |
| 58 | '187' => "\xBB", |
| 59 | '189' => "\xBD", |
| 60 | '900' => "\xB4", |
| 61 | '901' => "\xB5", |
| 62 | '902' => "\xB6", |
| 63 | '904' => "\xB8", |
| 64 | '905' => "\xB9", |
| 65 | '906' => "\xBA", |
| 66 | '908' => "\xBC", |
| 67 | '910' => "\xBE", |
| 68 | '911' => "\xBF", |
| 69 | '912' => "\xC0", |
| 70 | '913' => "\xC1", |
| 71 | '914' => "\xC2", |
| 72 | '915' => "\xC3", |
| 73 | '916' => "\xC4", |
| 74 | '917' => "\xC5", |
| 75 | '918' => "\xC6", |
| 76 | '919' => "\xC7", |
| 77 | '920' => "\xC8", |
| 78 | '921' => "\xC9", |
| 79 | '922' => "\xCA", |
| 80 | '923' => "\xCB", |
| 81 | '924' => "\xCC", |
| 82 | '925' => "\xCD", |
| 83 | '926' => "\xCE", |
| 84 | '927' => "\xCF", |
| 85 | '928' => "\xD0", |
| 86 | '929' => "\xD1", |
| 87 | '931' => "\xD3", |
| 88 | '932' => "\xD4", |
| 89 | '933' => "\xD5", |
| 90 | '934' => "\xD6", |
| 91 | '935' => "\xD7", |
| 92 | '936' => "\xD8", |
| 93 | '937' => "\xD9", |
| 94 | '938' => "\xDA", |
| 95 | '939' => "\xDB", |
| 96 | '940' => "\xDC", |
| 97 | '941' => "\xDD", |
| 98 | '942' => "\xDE", |
| 99 | '943' => "\xDF", |
| 100 | '944' => "\xE0", |
| 101 | '945' => "\xE1", |
| 102 | '946' => "\xE2", |
| 103 | '947' => "\xE3", |
| 104 | '948' => "\xE4", |
| 105 | '949' => "\xE5", |
| 106 | '950' => "\xE6", |
| 107 | '951' => "\xE7", |
| 108 | '952' => "\xE8", |
| 109 | '953' => "\xE9", |
| 110 | '954' => "\xEA", |
| 111 | '955' => "\xEB", |
| 112 | '956' => "\xEC", |
| 113 | '957' => "\xED", |
| 114 | '958' => "\xEE", |
| 115 | '959' => "\xEF", |
| 116 | '960' => "\xF0", |
| 117 | '961' => "\xF1", |
| 118 | '962' => "\xF2", |
| 119 | '963' => "\xF3", |
| 120 | '964' => "\xF4", |
| 121 | '965' => "\xF5", |
| 122 | '966' => "\xF6", |
| 123 | '967' => "\xF7", |
| 124 | '968' => "\xF8", |
| 125 | '969' => "\xF9", |
| 126 | '970' => "\xFA", |
| 127 | '971' => "\xFB", |
| 128 | '972' => "\xFC", |
| 129 | '973' => "\xFD", |
| 130 | '974' => "\xFE", |
| 131 | '8213' => "\xAF", |
| 132 | '8216' => "\xA1", |
| 133 | '8217' => "\xA2"); |
| 134 | |
| 135 | |
| 136 | if (array_key_exists($var,$iso88597chars)) { |
| 137 | $ret=$iso88597chars[$var]; |
| 138 | } else { |
| 139 | $ret='?'; |
| 140 | } |
| 141 | return $ret; |
| 142 | } |