Location: PHPKode > scripts > Turkish Soundex > D3Soundex.php
<?php
 
  /**
 * @name        D3Linq | Linq In Php
 * @version     1.0.1
 * @author      Tufan Bar&#305;&#351; YILDIRIM 
 * @link        htpp://www.tufyta.com
 * @since       20.10.2009
 * v1.0
 * ======
 * - &#304;lk Soundex Denemem.
 */
 
 class D3Soundex{

     const  AEIO    ='AEI&#304;OÖUÜY&#305;ü ',
            BPDT    ='BPDT',
            GKH     ='GK&#286;&#287;H',
            SZ      ='SZ&#350;&#351;',
            CJ      ='CJÇç',
            FV      ='FV',
            LR      ='LR',
            MN      ='MN';
            
      private   $_hassasiyet=50,
                $_ilkharf,
                $_kalan,
                $_deger,
                $_mixdeger,
                $_maxdeger,
                $_metin,
                $_elemanlar,
                $_zip,
                $_sade,
                $_grep;
       
      public function D3Soundex($hassasiyet){          
          if($hassasiyet<0 || $hassasiyet>100){
              $this->Hata('Hassasiyet De&#287;eri 0 ile 100 aras&#305;nda Bir De&#287;er Alabilir.');
          }
          $this->_hassasiyet=$hassasiyet;
          $this->ElemanOlustur();
                
      } 
      
      public function Metin($metin){
            $this->_metin=$metin;
            $this->_ilkharf=$metin[0];
            $this->_kalan=substr($metin,1,strlen($metin));
            
            $this->Sadelestir();
            $this->AdamEt($this->Tart($metin));
            return $this;
      }
      
      private  function Sadelestir(){
            $this->_sade=preg_replace('/.+/i','\1',$this->_metin);
      }
      
      private function Zip($Metin){
          $Metin=preg_replace('/[^'.$this->_grep.']/i','',$Metin);
              return $this->_zip=preg_replace('/['.self::AEIO.']+/i',$this->_elemanlar[self::AEIO],$Metin); 
      }
      
      private function Tart($Metin){
             foreach ($this->_elemanlar as $goruntu=>$kilo){
                   $Metin=preg_replace('/['.$goruntu.']+/i',$kilo,$Metin);
             }
             return $Metin;
      }
      
      private function AdamEt($TartilmisMetin){
          $Basamak=min(10,max(4,floor(strlen($this->Zip($Metin))*$this->_hassasiyet/100)));
          $this->_deger=substr($TartilmisMetin,0,$Basamak);
          return strtoupper($this->_ilkharf).$this->_deger;
      }
      
      public function Deger(){
          return $this->_deger;
      }
      
      public function Soundex(){
          return strtoupper($this->_ilkharf).$this->Deger();
      }
      
      private function ElemanOlustur(){
         $this->_elemanlar=array(
             self::AEIO=>'',
             self::BPDT=>5,                           
             self::SZ=>3,                             
             self::MN=>4,                              
             self::GKH=>8,                              
             self::CJ=>6,                                
             self::FV=>2,                               
             self::LR=>7,
             self::MN=>1,                               
         );
         $this->_grep=str_replace(' ','',implode(' ',array_keys($this->_elemanlar)));
         
         
      }
      
      
      private function Hata($hatametni){
          echo '<b>Hata</b> :  '.$hatametni;
      } 
      
     
 }
 /**
 * Examlpe
 * 
 * @var D3Soundex
 */
 $s=new D3Soundex(100);
 $s->Metin('Bunu mu demek istediniz ?');
 echo "Bunu mu demek istediniz ? =>Soundex Degeri : ".$s->Soundex()." A&#287;&#305;rl&#305;k : ".$s->Deger()."<br>";
 $s->Metin('Bunu demek mi istediniz ?');
 echo "Bunu demek mi istediniz ?=>Soundex Degeri : ".$s->Soundex()." A&#287;&#305;rl&#305;k : ".$s->Deger()."<br>";   
?>
Return current item: Turkish Soundex