<?php
// ----------------------------------------------------------------------
// Copyright (C) 2006 by Khaled Al-Shamaa.
// http://www.al-shamaa.com/
// ----------------------------------------------------------------------
// LICENSE
// This program is open source product; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
// Class Name: Arabic Character Set Converter
// Filename: ArCharsetC.class.php
// Original Author(s): Khaled Al-Sham'aa <hide@address.com>
// Purpose: Convert a given Arabic string from one Arabic character set to another,
// those available character sets includes the most popular three:
// Windows-1256, ISO 8859-6, and UTF-8
// ----------------------------------------------------------------------
class ArCharsetC {
var $windows1256 = array();
var $iso88596 = array();
var $utf8 = array();
function ArCharsetC(){
$this->windows1256[0] = 'Ð';
$this->windows1256[1] = 'Ï';
$this->windows1256[2] = 'Ì';
$this->windows1256[3] = 'Í';
$this->windows1256[4] = 'Î';
$this->windows1256[5] = 'å';
$this->windows1256[6] = 'Ú';
$this->windows1256[7] = 'Û';
$this->windows1256[8] = 'Ý';
$this->windows1256[9] = 'Þ';
$this->windows1256[10] = 'Ë';
$this->windows1256[11] = 'Õ';
$this->windows1256[12] = 'Ö';
$this->windows1256[13] = 'Ø';
$this->windows1256[14] = 'ß';
$this->windows1256[15] = 'ã';
$this->windows1256[16] = 'ä';
$this->windows1256[17] = 'Ê';
$this->windows1256[18] = 'Ç';
$this->windows1256[19] = 'á';
$this->windows1256[20] = 'È';
$this->windows1256[21] = 'í';
$this->windows1256[22] = 'Ó';
$this->windows1256[23] = 'Ô';
$this->windows1256[24] = 'Ù';
$this->windows1256[25] = 'Ò';
$this->windows1256[26] = 'æ';
$this->windows1256[27] = 'É';
$this->windows1256[28] = 'ì';
$this->windows1256[29] = 'Ñ';
$this->windows1256[30] = 'Ä';
$this->windows1256[31] = 'Á';
$this->windows1256[32] = 'Æ';
$this->windows1256[33] = 'ø';
$this->windows1256[34] = 'ó';
$this->windows1256[35] = 'ð';
$this->windows1256[36] = 'ñ';
$this->windows1256[37] = 'Å';
$this->windows1256[38] = 'ö';
$this->windows1256[39] = 'ò';
$this->windows1256[40] = 'Ã';
$this->windows1256[41] = 'Ü';
$this->windows1256[42] = '¡';
$this->windows1256[43] = 'ú';
$this->windows1256[44] = 'Â';
$this->windows1256[45] = ',';
$this->windows1256[46] = '.';
$this->windows1256[47] = '¿';
$this->iso88596[0] = 'Ð';
$this->iso88596[1] = 'Ï';
$this->iso88596[2] = 'Ì';
$this->iso88596[3] = 'Í';
$this->iso88596[4] = 'Î';
$this->iso88596[5] = 'ç';
$this->iso88596[6] = 'Ù';
$this->iso88596[7] = 'Ú';
$this->iso88596[8] = 'á';
$this->iso88596[9] = 'â';
$this->iso88596[10] = 'Ë';
$this->iso88596[11] = 'Õ';
$this->iso88596[12] = 'Ö';
$this->iso88596[13] = '×';
$this->iso88596[14] = 'ã';
$this->iso88596[15] = 'å';
$this->iso88596[16] = 'æ';
$this->iso88596[17] = 'Ê';
$this->iso88596[18] = 'Ç';
$this->iso88596[19] = 'ä';
$this->iso88596[20] = 'È';
$this->iso88596[21] = 'ê';
$this->iso88596[22] = 'Ó';
$this->iso88596[23] = 'Ô';
$this->iso88596[24] = 'Ø';
$this->iso88596[25] = 'Ò';
$this->iso88596[26] = 'è';
$this->iso88596[27] = 'É';
$this->iso88596[28] = 'é';
$this->iso88596[29] = 'Ñ';
$this->iso88596[30] = 'Ä';
$this->iso88596[31] = 'Á';
$this->iso88596[32] = 'Æ';
$this->iso88596[33] = 'ñ';
$this->iso88596[34] = 'î';
$this->iso88596[35] = 'ë';
$this->iso88596[36] = 'ì';
$this->iso88596[37] = 'Å';
$this->iso88596[38] = 'ð';
$this->iso88596[39] = 'í';
$this->iso88596[40] = 'Ã';
$this->iso88596[41] = 'à';
$this->iso88596[42] = '¬';
$this->iso88596[43] = 'ò';
$this->iso88596[44] = 'Â';
$this->iso88596[45] = ',';
$this->iso88596[46] = '.';
$this->iso88596[47] = '¿';
$this->utf8[0] = 'ذ';
$this->utf8[1] = 'د';
$this->utf8[2] = 'ج';
$this->utf8[3] = 'Ø';
$this->utf8[4] = 'Ø®';
$this->utf8[5] = 'Ù';
$this->utf8[6] = 'ع';
$this->utf8[7] = 'غ';
$this->utf8[8] = 'Ù';
$this->utf8[9] = 'Ù';
$this->utf8[10] = 'Ø«';
$this->utf8[11] = 'ص';
$this->utf8[12] = 'ض';
$this->utf8[13] = 'Ø·';
$this->utf8[14] = 'Ù';
$this->utf8[15] = 'Ù
';
$this->utf8[16] = 'Ù';
$this->utf8[17] = 'ت';
$this->utf8[18] = 'ا';
$this->utf8[19] = 'Ù';
$this->utf8[20] = 'ب';
$this->utf8[21] = 'Ù';
$this->utf8[22] = 'س';
$this->utf8[23] = 'Ø´';
$this->utf8[24] = 'ظ';
$this->utf8[25] = 'ز';
$this->utf8[26] = 'Ù';
$this->utf8[27] = 'Ø©';
$this->utf8[28] = 'Ù';
$this->utf8[29] = 'ر';
$this->utf8[30] = 'ؤ';
$this->utf8[31] = 'Ø¡';
$this->utf8[32] = 'ئ';
$this->utf8[33] = 'Ù';
$this->utf8[34] = 'Ù';
$this->utf8[35] = 'Ù';
$this->utf8[36] = 'Ù';
$this->utf8[37] = 'Ø¥';
$this->utf8[38] = 'Ù';
$this->utf8[39] = 'Ù';
$this->utf8[40] = 'Ø£';
$this->utf8[41] = 'Ù';
$this->utf8[42] = 'Ø';
$this->utf8[43] = 'Ù';
$this->utf8[44] = 'Ø¢';
$this->utf8[45] = ',';
$this->utf8[46] = '.';
$this->utf8[47] = 'Ø';
}
function win2iso($string){
$chars = preg_split('//', $string);
foreach($chars as $char){
$key = array_search($char, $this->windows1256);
if(is_int($key)){ $converted .= $this->iso88596[$key]; }else{ $converted .= $char; }
}
return $converted;
}
function win2utf($string){
$chars = preg_split('//', $string);
foreach($chars as $char){
$key = array_search($char, $this->windows1256);
if(is_int($key)){ $converted .= $this->utf8[$key]; }else{ $converted .= $char; }
}
return $converted;
}
function iso2win($string){
$chars = preg_split('//', $string);
foreach($chars as $char){
$key = array_search($char, $this->iso88596);
if(is_int($key)){ $converted .= $this->windows1256[$key]; }else{ $converted .= $char; }
}
return $converted;
}
function iso2utf($string){
$chars = preg_split('//', $string);
foreach($chars as $char){
$key = array_search($char, $this->iso88596);
if(is_int($key)){ $converted .= $this->utf8[$key]; }else{ $converted .= $char; }
}
return $converted;
}
function utf2win($string){
$chars = preg_split('//', $string);
$cmp = false;
foreach($chars as $char){
$ascii = ord($char);
if(($ascii == 216 || $ascii == 217) && !$cmp){ $code = $char; $cmp = true; continue; }
if($cmp){
$code .= $char;
$cmp = false;
$key = array_search($code, $this->utf8);
if(is_int($key)){ $converted .= $this->windows1256[$key]; }
}else{
$converted .= $char;
}
}
return $converted;
}
function utf2iso($string){
$chars = preg_split('//', $string);
$cmp = false;
foreach($chars as $char){
$ascii = ord($char);
if(($ascii == 216 || $ascii == 217) && !$cmp){ $code = $char; $cmp = true; continue; }
if($cmp){
$code .= $char;
$cmp = false;
$key = array_search($code, $this->utf8);
if(is_int($key)){ $converted .= $this->iso88596[$key]; }
}else{
$converted .= $char;
}
}
return $converted;
}
}
?>