Location: PHPKode > scripts > ArKeySwap > arkeyswap/php5/ArKeySwap.class.php
<?php
// ----------------------------------------------------------------------
// Copyright (C) 2007 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 Keyboard Swapping Language
// Filename:   ArKeySwap.class.php
// Original    Author(s): Khaled Al-Sham'aa <hide@address.com>
// Purpose:    Convert keyboard language programmatically (English - Arabic)
// ----------------------------------------------------------------------

class ArKeySwap {
      private $swap_ae = array();
      private $swap_ea = array();

      public function ArKeySwap(){
          $this->swap_ea['`'] = 'Ð';
          $this->swap_ea['q'] = 'Ö';
          $this->swap_ea['w'] = 'Õ';
          $this->swap_ea['e'] = 'Ë';
          $this->swap_ea['r'] = 'Þ';
          $this->swap_ea['t'] = 'Ý';
          $this->swap_ea['y'] = 'Û';
          $this->swap_ea['u'] = 'Ú';
          $this->swap_ea['i'] = 'å';
          $this->swap_ea['o'] = 'Î';
          $this->swap_ea['p'] = 'Í';
          $this->swap_ea['['] = 'Ì';
          $this->swap_ea[']'] = 'Ï';
          $this->swap_ea['a'] = 'Ô';
          $this->swap_ea['s'] = 'Ó';
          $this->swap_ea['d'] = 'í';
          $this->swap_ea['f'] = 'È';
          $this->swap_ea['g'] = 'á';
          $this->swap_ea['h'] = 'Ç';
          $this->swap_ea['j'] = 'Ê';
          $this->swap_ea['k'] = 'ä';
          $this->swap_ea['l'] = 'ã';
          $this->swap_ea[';'] = 'ß';
          $this->swap_ea['\'']= 'Ø';
          $this->swap_ea['z'] = 'Æ';
          $this->swap_ea['x'] = 'Á';
          $this->swap_ea['c'] = 'Ä';
          $this->swap_ea['v'] = 'Ñ';
          $this->swap_ea['b'] = 'áÇ';
          $this->swap_ea['n'] = 'ì';
          $this->swap_ea['m'] = 'É';
          $this->swap_ea[','] = 'æ';
          $this->swap_ea['.'] = 'Ò';
          $this->swap_ea['/'] = 'Ù';
          
          $this->swap_ea['~'] = 'ø';
          $this->swap_ea['Q'] = 'ó';
          $this->swap_ea['W'] = 'ð';
          $this->swap_ea['E'] = 'õ';
          $this->swap_ea['R'] = 'ñ';
          $this->swap_ea['T'] = 'áÅ';
          $this->swap_ea['Y'] = 'Å';
          $this->swap_ea['U'] = '‘';
          $this->swap_ea['I'] = '÷';
          $this->swap_ea['O'] = '×';
          $this->swap_ea['P'] = 'º';
          $this->swap_ea['{'] = '<';
          $this->swap_ea['}'] = '>';
          $this->swap_ea['A'] = 'ö';
          $this->swap_ea['S'] = 'ò';
          $this->swap_ea['D'] = ']';
          $this->swap_ea['F'] = '[';
          $this->swap_ea['G'] = 'áÃ';
          $this->swap_ea['H'] = 'Ã';
          $this->swap_ea['J'] = 'Ü';
          $this->swap_ea['K'] = '¡';
          $this->swap_ea['L'] = '/';
          $this->swap_ea[':'] = ':';
          $this->swap_ea['"'] = '"';
          $this->swap_ea['Z'] = '~';
          $this->swap_ea['X'] = 'ú';
          $this->swap_ea['C'] = '}';
          $this->swap_ea['V'] = '{';
          $this->swap_ea['B'] = 'áÂ';
          $this->swap_ea['N'] = 'Â';
          $this->swap_ea['M'] = '’';
          $this->swap_ea['<'] = ',';
          $this->swap_ea['>'] = '.';
          $this->swap_ea['?'] = '¿';

          $this->swap_ae['Ð'] = '`';
          $this->swap_ae['Ö'] = 'q';
          $this->swap_ae['Õ'] = 'w';
          $this->swap_ae['Ë'] = 'e';
          $this->swap_ae['Þ'] = 'r';
          $this->swap_ae['Ý'] = 't';
          $this->swap_ae['Û'] = 'y';
          $this->swap_ae['Ú'] = 'u';
          $this->swap_ae['å'] = 'i';
          $this->swap_ae['Î'] = 'o';
          $this->swap_ae['Í'] = 'p';
          $this->swap_ae['Ì'] = '[';
          $this->swap_ae['Ï'] = ']';
          $this->swap_ae['Ô'] = 'a';
          $this->swap_ae['Ó'] = 's';
          $this->swap_ae['í'] = 'd';
          $this->swap_ae['È'] = 'f';
          $this->swap_ae['á'] = 'g';
          $this->swap_ae['Ç'] = 'h';
          $this->swap_ae['Ê'] = 'j';
          $this->swap_ae['ä'] = 'k';
          $this->swap_ae['ã'] = 'l';
          $this->swap_ae['ß'] = ';';
          $this->swap_ae['Ø'] = '\'';
          $this->swap_ae['Æ'] = 'z';
          $this->swap_ae['Á'] = 'x';
          $this->swap_ae['Ä'] = 'c';
          $this->swap_ae['Ñ'] = 'v';
          $this->swap_ae['áÇ']= 'b';
          $this->swap_ae['ì'] = 'n';
          $this->swap_ae['É'] = 'm';
          $this->swap_ae['æ'] = ',';
          $this->swap_ae['Ò'] = '.';
          $this->swap_ae['Ù'] = '/';
          
          $this->swap_ae['ø'] = '~';
          $this->swap_ae['ó'] = 'Q';
          $this->swap_ae['ð'] = 'W';
          $this->swap_ae['õ'] = 'E';
          $this->swap_ae['ñ'] = 'R';
          $this->swap_ae['áÅ']= 'T';
          $this->swap_ae['Å'] = 'Y';
          $this->swap_ae['‘'] = 'U';
          $this->swap_ae['÷'] = 'I';
          $this->swap_ae['×'] = 'O';
          $this->swap_ae['º'] = 'P';
          $this->swap_ae['<'] = '{';
          $this->swap_ae['>'] = '}';
          $this->swap_ae['ö'] = 'A';
          $this->swap_ae['ò'] = 'S';
          $this->swap_ae[']'] = 'D';
          $this->swap_ae['['] = 'F';
          $this->swap_ae['áÃ']= 'G';
          $this->swap_ae['Ã'] = 'H';
          $this->swap_ae['Ü'] = 'J';
          $this->swap_ae['¡'] = 'K';
          $this->swap_ae['/'] = 'L';
          $this->swap_ae[':'] = ':';
          $this->swap_ae['"'] = '"';
          $this->swap_ae['~'] = 'Z';
          $this->swap_ae['ú'] = 'X';
          $this->swap_ae['}'] = 'C';
          $this->swap_ae['{'] = 'V';
          $this->swap_ae['áÂ']= 'B';
          $this->swap_ae['Â'] = 'N';
          $this->swap_ae['’'] = 'M';
          $this->swap_ae[','] = '<';
          $this->swap_ae['.'] = '>';
          $this->swap_ae['¿'] = '?';
      }

      public function swap_ae($text){
          $output = '';

	  $text   = str_replace('áÇ', 'b', $text);
	  $text   = str_replace('áÂ', 'B', $text);
	  $text   = str_replace('áÃ', 'G', $text);
	  $text   = str_replace('áÅ', 'T', $text);

          $chars  = preg_split('//', $text, -1, PREG_SPLIT_NO_EMPTY);

          foreach ($chars as $char){
              if($this->swap_ae[$char]){
                 $output .= $this->swap_ae[$char];
              }else{
                 $output .= $char;
              }
          }

          return $output;
      }

      public function swap_ea($text){
          $output = '';
          $chars  = preg_split('//', $text, -1, PREG_SPLIT_NO_EMPTY);

          foreach ($chars as $char){
              if($this->swap_ea[$char]){
                 $output .= $this->swap_ea[$char];
              }else{
                 $output .= $char;
              }
          }

          return $output;
      }
}

?>
Return current item: ArKeySwap