2 #====================================================================================================#
3 # ar2uni v0.1 (Arabic-win1256 encoder to Unicode) #
4 #====================================================================================================#
6 # This is PHP function for covert Arabic encoding string to #
7 # unicode that can use to show Arabic charactor in function ImageTTFText(). #
8 # It Tested and worked with Multilanguage arial.ttf V2.98 #
11 # version 0.1 : First release. created on ( 22/01/2004) By Walid Fathalla #
13 # Bug Report and Suggestion to: #
15 # fathalla_w@hotmail.com #
17 #====================================================================================================#
19 # include_once($root_path.'inc_ttf_ar2uni.php'); #
20 # ImageTTFText ($image, 8, 0, 3, 15, $white, "arial.ttf",ar2uni("$ArabicString")); #
21 #====================================================================================================#
22 # For Arabic Website: If you thing this module useful to you, please send to #
23 # me back to my email fathalla_w@hotmail.com. #
25 #====================================================================================================#
27 #================================================// Arabic character maps//=============================================
28 $ar2unimap = array( // One bit character isolated form
29 ',' => "،", 'º' => "؛", '¿' => "؟", 'Á' => "ء", 'Â' => "آ", 'Ã' => "أ", 'Ä' => "ؤ",
30 'Å' => "إ", 'Æ' => "ئ", 'Ç' => "ا", 'È' => "ب", 'É' => "ة", 'Ê' => "ت", 'Ë' => "ث",
31 'Ì' => "ج", 'Í' => "ح", 'Î' => "خ", 'Ï' => "د", 'Ð' => "ذ", 'Ñ' => "ر", 'Ò' => "ز",
32 'Ó' => "س", 'Ô' => "ش", 'Õ' => "ص", 'Ö' => "ض", 'Ø' => "ط", 'Ù' => "ظ", 'Ú' => "ع",
33 'Û' => "غ", 'Ü' => "ـ", 'Ý' => "ف", 'Þ' => "ق", 'ß' => "ك", 'á' => "ل", 'ã' => "م",
34 'ä' => "ن", 'å' => "ه", 'æ' => "و", 'ì' => "ى", 'í' => "ي", 'ð' => "ً", 'ñ' => "ٌ",
35 'ò' => "ٍ", 'ó' => "َ", 'õ' => "ُ", 'ö' => "ِ", 'ø' => "ّ", 'ú' => "ْ");
37 $ar2unimap2 = array( // One bit character initial form
38 'Â' => "ﺁ", 'Ã' => "ﺃ", 'Ä' => "ﺅ", 'Å' => "ﺇ", 'Æ' => "ﺋ", 'Ç' => "ﺍ", 'È' => "ﺑ",
39 'Ê' => "ﺗ", 'Ë' => "ﺛ", 'Ì' => "ﺟ", 'Í' => "ﺣ", 'Î' => "ﺧ", 'Ï' => "ﺩ", 'Ð' => "ﺫ",
40 'Ñ' => "ﺭ", 'Ò' => "ﺯ", 'Ó' => "ﺳ", 'Ô' => "ﺷ", 'Õ' => "ﺻ", 'Ö' => "ﺿ", 'Ø' => "ﻃ",
41 'Ù' => "ﻇ", 'Ú' => "ﻋ", 'Û' => "ﻏ", 'Ý' => "ﻓ", 'Þ' => "ﻗ", 'ß' => "ﻛ", 'á' => "ﻟ",
42 'ã' => "ﻣ", 'ä' => "ﻧ", 'å' => "ﻫ", 'æ' => "ﻭ", 'í' => "ﻳ");
44 $ar2unimap3 = array( // One bit character medial form
45 'Æ' => "ﺌ", 'È' => "ﺒ", 'Ê' => "ﺘ", 'Ë' => "ﺜ", 'Ì' => "ﺠ", 'Í' => "ﺤ", 'Î' => "ﺨ",
46 'Ó' => "ﺴ", 'Ô' => "ﺸ", 'Õ' => "ﺼ", 'Ö' => "ﻀ", 'Ø' => "ﻄ", 'Ù' => "ﻈ", 'Ú' => "ﻌ",
47 'Û' => "ﻐ", 'Ý' => "ﻔ", 'Þ' => "ﻘ", 'ß' => "ﻜ", 'á' => "ﻠ", 'ã' => "ﻤ", 'ä' => "ﻨ",
48 'å' => "ﻬ", 'í' => "ﻴ");
50 $ar2unimap4 = array( // One bit character final form
51 'Â' => "ﺂ", 'Ã' => "ﺄ", 'Ä' => "ﺆ", 'Å' => "ﺈ", 'Æ' => "ﺊ", 'Ç' => "ﺎ", 'È' => "ﺐ",
52 'É' => "ﺔ", 'Ê' => "ﺖ", 'Ë' => "ﺚ", 'Ì' => "ﺞ", 'Í' => "ﺢ", 'Î' => "ﺦ", 'Ï' => "ﺪ",
53 'Ð' => "ﺬ", 'Ñ' => "ﺮ", 'Ò' => "ﺰ", 'Ó' => "ﺲ", 'Ô' => "ﺶ", 'Õ' => "ﺺ", 'Ö' => "ﺾ",
54 'Ø' => "ﻂ", 'Ù' => "ﻆ", 'Ú' => "ﻊ", 'Û' => "ﻎ", 'Ý' => "ﻒ", 'Þ' => "ﻖ", 'ß' => "ﻚ",
55 'á' => "ﻞ", 'ã' => "ﻢ", 'ä' => "ﻦ", 'å' => "ﻪ", 'æ' => "ﻮ", 'ì' => "ﻰ", 'í' => "ﻲ");
57 $ar2unimap5 = array( // Two bit character isolated & initial form
63 $ar2unimap6 = array( // Two bit character final form
68 #================================================// end of character maps//=============================================
70 function ar2uni($sti){
71 global $ar2unimap,$ar2unimap2,$ar2unimap3,$ar2unimap4,$ar2unimap5,$ar2unimap6;
73 # START: (FIX) By Tarek Alwerfally on 16/12/2005
74 if( ($sti[0]>='A' && $sti[0]<='Z') ||
($sti[0]>='a' && $sti[0]<='z') ) return( $sti );
75 # END: By Tarek Alwerfally on 16/12/2005
77 # Patch by Elpidio 2004-02-06
78 # If the text is encoded in unicode, reverse the order and return
79 if(strstr($sti,'&#')&&strstr($sti,';')){
80 $buf=explode(';',$sti);
81 $buf=array_reverse($buf);
82 # Remove the first element which is empty
84 $sti=implode(';',$buf);
85 return trim($sti).';';
95 for ($i=1; $i < $len-1; $i++
){
96 #=========================// for one bit character have 4 forms//================
97 if($ar2unimap3[$sti{$i}]){
99 if($sti{$i-1}==" " and $sti{$i+
1}==" "){
100 $sto .=$ar2unimap[$sti{$i}];
102 }elseif($sti{$i-1}==" "){
104 if($ar2unimap3[$sti{$i+
1}]){
105 $sto .=$ar2unimap4[$sti{$i}];
107 $sto .=$ar2unimap[$sti{$i}];
110 }elseif($sti{$i+
1}==" "){
111 $sto .=$ar2unimap2[$sti{$i}];
114 if($ar2unimap3[$sti{$i+
1}]){
115 $sto .=$ar2unimap3[$sti{$i}];
117 $sto .=$ar2unimap2[$sti{$i}];
120 #=========================// for one bit character have 3 forms//================
121 }elseif($ar2unimap2[$sti{$i}]){
123 if($sti{$i-1}==" " and $sti{$i+
1}==" "){
124 $sto .=$ar2unimap[$sti{$i}];
126 }elseif($sti{$i-1}==" "){
128 if($ar2unimap3[$sti{$i+
1}]){
130 if($sti{$i}=="Â" and $sti{$i+
1}=="á"){// to check lam alef Two bit character
131 if($ar2unimap3[$sti{$i+
2}]){
132 $sto .=$ar2unimap6["áÂ"];
134 $sto .=$ar2unimap5["áÂ"];
137 }elseif($sti{$i}=="Ã" and $sti{$i+
1}=="á"){
138 if($ar2unimap3[$sti{$i+
2}]){
139 $sto .=$ar2unimap6["áÃ"];
141 $sto .=$ar2unimap5["áÃ"];
144 }elseif($sti{$i}=="Å" and $sti{$i+
1}=="á"){
145 if($ar2unimap3[$sti{$i+
2}]){
146 $sto .=$ar2unimap6["áÅ"];
148 $sto .=$ar2unimap5["áÅ"];
151 }elseif($sti{$i}=="Ç" and $sti{$i+
1}=="á"){
152 if($ar2unimap3[$sti{$i+
2}]){
153 $sto .=$ar2unimap6["áÇ"];
155 $sto .=$ar2unimap5["áÇ"];
159 $sto .=$ar2unimap4[$sti{$i}];
163 $sto .=$ar2unimap[$sti{$i}];
166 }elseif($sti{$i+
1}==" "){
167 $sto .=$ar2unimap[$sti{$i}];
170 if($ar2unimap3[$sti{$i+
1}]){
172 if($sti{$i}=="Â" and $sti{$i+
1}=="á"){// to check lam alef Two bit character
173 if($ar2unimap3[$sti{$i+
2}]){
174 $sto .=$ar2unimap6["áÂ"];
176 $sto .=$ar2unimap5["áÂ"];
179 }elseif($sti{$i}=="Ã" and $sti{$i+
1}=="á"){
180 if($ar2unimap3[$sti{$i+
2}]){
181 $sto .=$ar2unimap6["áÃ"];
183 $sto .=$ar2unimap5["áÃ"];
186 }elseif($sti{$i}=="Å" and $sti{$i+
1}=="á"){
187 if($ar2unimap3[$sti{$i+
2}]){
188 $sto .=$ar2unimap6["áÅ"];
190 $sto .=$ar2unimap5["áÅ"];
193 }elseif($sti{$i}=="Ç" and $sti{$i+
1}=="á"){
194 if($ar2unimap3[$sti{$i+
2}]){
195 $sto .=$ar2unimap6["áÇ"];
197 $sto .=$ar2unimap5["áÇ"];
201 $sto .=$ar2unimap4[$sti{$i}];
205 $sto .=$ar2unimap[$sti{$i}];
208 #=========================// for one bit character have 2forms//================
209 }elseif($ar2unimap4[$sti{$i}]){
211 if($sti{$i-1}==" " and $sti{$i+
1}==" "){
212 $sto .=$ar2unimap[$sti{$i}];
214 }elseif($sti{$i-1}==" "){
216 if($ar2unimap3[$sti{$i+
1}]){
217 $sto .=$ar2unimap4[$sti{$i}];
219 $sto .=$ar2unimap[$sti{$i}];
222 }elseif($sti{$i+
1}==" "){
223 $sto .=$ar2unimap[$sti{$i}];
226 if($ar2unimap3[$sti{$i+
1}]){
227 $sto .=$ar2unimap4[$sti{$i}];
229 $sto .=$ar2unimap[$sti{$i}];
232 #=========================// for one bit character have 1 form//================
233 }elseif($ar2unimap[$sti{$i}]){
234 $sto .=$ar2unimap[$sti{$i}];