کلاس تبدیل اسم های انگلیسی به فارسی - انجمن PHP


ارسال پاسخ 
کلاس تبدیل اسم های انگلیسی به فارسی
۲۶-۲-۱۳۹۴, ۱۲:۲۰ صبح
ارسال: #1
کلاس تبدیل اسم های انگلیسی به فارسی
کلاس تبدیل اسم های انگلیسی به فارسی که توسط دوست خوبمان پیمان فرهمند کیا نوشته شده . 


کد php:
<?php
// ----------------------------------------------------------------------
// Copyright (C) 2014-2015 by Peyman Farahmand
// http://www.porcen.ir
// ----------------------------------------------------------------------

class PersianNames {
      var 
$enPatterns     = array();
      var 
$enReplacements = array();

      function 
PersianNames(){
          
array_push($this->enPatterns'/^au/'); array_push($this->enReplacements'ا');
          
array_push($this->enPatterns'/^a/'); array_push($this->enReplacements'ا');
          
array_push($this->enPatterns'/^e/'); array_push($this->enReplacements'ا');
          
array_push($this->enPatterns'/^i/'); array_push($this->enReplacements'ا');
          
array_push($this->enPatterns'/^mc/'); array_push($this->enReplacements'ماك');
          
array_push($this->enPatterns'/^o/'); array_push($this->enReplacements'او');
          
array_push($this->enPatterns'/^u/'); array_push($this->enReplacements'ا');
          
array_push($this->enPatterns'/^wr/'); array_push($this->enReplacements'ر');
          
array_push($this->enPatterns'/ough$/'); array_push($this->enReplacements'ه');
          
array_push($this->enPatterns'/ough/'); array_push($this->enReplacements'او');
          
array_push($this->enPatterns'/alk/'); array_push($this->enReplacements'وك');
          
array_push($this->enPatterns'/ois/'); array_push($this->enReplacements'وا');
          
array_push($this->enPatterns'/sch/'); array_push($this->enReplacements'ش');
          
array_push($this->enPatterns'/tio/'); array_push($this->enReplacements'ش');
          
array_push($this->enPatterns'/ai/'); array_push($this->enReplacements'اي');
          
array_push($this->enPatterns'/au/'); array_push($this->enReplacements'او');
          
array_push($this->enPatterns'/bb/'); array_push($this->enReplacements'ب');
          
array_push($this->enPatterns'/cc/'); array_push($this->enReplacements'ك');
          
array_push($this->enPatterns'/ce/'); array_push($this->enReplacements'س');
          
array_push($this->enPatterns'/ci/'); array_push($this->enReplacements'سي');
          
array_push($this->enPatterns'/cy/'); array_push($this->enReplacements'سي');
          
array_push($this->enPatterns'/ch/'); array_push($this->enReplacements'چ');
          
array_push($this->enPatterns'/ck/'); array_push($this->enReplacements'ك');
          
array_push($this->enPatterns'/dd/'); array_push($this->enReplacements'د');
          
array_push($this->enPatterns'/ea/'); array_push($this->enReplacements'ي');
          
array_push($this->enPatterns'/ee/'); array_push($this->enReplacements'ي');
          
array_push($this->enPatterns'/ey/'); array_push($this->enReplacements'اي');
          
array_push($this->enPatterns'/ff/'); array_push($this->enReplacements'ف');
          
array_push($this->enPatterns'/ge/'); array_push($this->enReplacements'ج');
          
array_push($this->enPatterns'/gi/'); array_push($this->enReplacements'گي');
          
array_push($this->enPatterns'/gg/'); array_push($this->enReplacements'گ');
          
array_push($this->enPatterns'/gh/'); array_push($this->enReplacements'ف');
          
array_push($this->enPatterns'/gn/'); array_push($this->enReplacements'گن');
          
array_push($this->enPatterns'/ie/'); array_push($this->enReplacements'ي');
          
array_push($this->enPatterns'/kk/'); array_push($this->enReplacements'ك');
          
array_push($this->enPatterns'/kh/'); array_push($this->enReplacements'خ');
          
array_push($this->enPatterns'/ll/'); array_push($this->enReplacements'ل');
          
array_push($this->enPatterns'/mm/'); array_push($this->enReplacements'م');
          
array_push($this->enPatterns'/nn/'); array_push($this->enReplacements'ن');
          
array_push($this->enPatterns'/oo/'); array_push($this->enReplacements'و');
          
array_push($this->enPatterns'/ou/'); array_push($this->enReplacements'و');
          
array_push($this->enPatterns'/ph/'); array_push($this->enReplacements'ف');
          
array_push($this->enPatterns'/pp/'); array_push($this->enReplacements'پ');
          
array_push($this->enPatterns'/qu/'); array_push($this->enReplacements'كو');
          
array_push($this->enPatterns'/rr/'); array_push($this->enReplacements'ر');
          
array_push($this->enPatterns'/sh/'); array_push($this->enReplacements'ش');
          
array_push($this->enPatterns'/ss/'); array_push($this->enReplacements'س');
          
array_push($this->enPatterns'/th/'); array_push($this->enReplacements'د');
          
array_push($this->enPatterns'/tt/'); array_push($this->enReplacements'ت');
          
array_push($this->enPatterns'/ue$/'); array_push($this->enReplacements'');
          
array_push($this->enPatterns'/wr/'); array_push($this->enReplacements'ر');
          
array_push($this->enPatterns'/a$/'); array_push($this->enReplacements'ه');
          
array_push($this->enPatterns'/a/'); array_push($this->enReplacements'ا');
          
array_push($this->enPatterns'/b/'); array_push($this->enReplacements'ب');
          
array_push($this->enPatterns'/c/'); array_push($this->enReplacements'ك');
          
array_push($this->enPatterns'/d/'); array_push($this->enReplacements'د');
          
array_push($this->enPatterns'/e/'); array_push($this->enReplacements'');
          
array_push($this->enPatterns'/f/'); array_push($this->enReplacements'ف');
          
array_push($this->enPatterns'/g/'); array_push($this->enReplacements'گ');
          
array_push($this->enPatterns'/h/'); array_push($this->enReplacements'ه');
          
array_push($this->enPatterns'/i/'); array_push($this->enReplacements'ي');
          
array_push($this->enPatterns'/j/'); array_push($this->enReplacements'ج');
          
array_push($this->enPatterns'/k/'); array_push($this->enReplacements'ك');
          
array_push($this->enPatterns'/l/'); array_push($this->enReplacements'ل');
          
array_push($this->enPatterns'/m/'); array_push($this->enReplacements'م');
          
array_push($this->enPatterns'/n/'); array_push($this->enReplacements'ن');
          
array_push($this->enPatterns'/o/'); array_push($this->enReplacements'و');
          
array_push($this->enPatterns'/p/'); array_push($this->enReplacements'پ');
          
array_push($this->enPatterns'/q/'); array_push($this->enReplacements'ك');
          
array_push($this->enPatterns'/r/'); array_push($this->enReplacements'ر');
          
array_push($this->enPatterns'/s$/'); array_push($this->enReplacements'س');
          
array_push($this->enPatterns'/s/'); array_push($this->enReplacements'س');
          
array_push($this->enPatterns'/t/'); array_push($this->enReplacements'ت');
          
array_push($this->enPatterns'/u/'); array_push($this->enReplacements'و');
          
array_push($this->enPatterns'/v/'); array_push($this->enReplacements'ف');
          
array_push($this->enPatterns'/w/'); array_push($this->enReplacements'و');
          
array_push($this->enPatterns'/x/'); array_push($this->enReplacements'كس');
          
array_push($this->enPatterns'/y/'); array_push($this->enReplacements'ي');
          
array_push($this->enPatterns'/z/'); array_push($this->enReplacements'ز');
      }

      function 
en2fa($string){
          
$string strtolower($string);
          
$words  explode(' '$string);
          
$string '';

          foreach(
$words as $word){
              
$string .= ' '.preg_replace($this->enPatterns$this->enReplacements$word);
          }

          return 
$string;
      }
}
?>



منبع : http://ume.ir/pfndesign
یافتن تمامی ارسال‌های این کاربر
نقل قول این ارسال در یک پاسخ
ارسال پاسخ 


پیام‌های داخل این موضوع
کلاس تبدیل اسم های انگلیسی به فارسی - شاهین سمیع عادل - ۲۶-۲-۱۳۹۴ ۱۲:۲۰ صبح

پرش به انجمن:


کاربرانِ درحال بازدید از این موضوع: 1 مهمان