예제 #1
0
 /**
  * calculate the soundex value of the string
  * @param $lang string			calculate soundex using a specific language specification (actually french/us only)
  * @param $source string 		string to calculate the soundex 
  * @return string 				the soundex value
  **/
 function createSoundex($lang = 'en')
 {
     $s = $this->toString();
     if ($lang == 'fr') {
         if (strlen($s) > 0) {
             $s = StringBuffer::removeAccents($s);
             $s = StringBuffer::keepSpaceOnly($s);
             $s = StringBuffer::toUpperCase($s);
             $s = preg_replace('/(.)\\1/', '\\1', $s);
             $first_letter = $s[0];
             $s = ereg_replace('AEIOUYHW', '', $s);
             $s = strtr('112223345567788899', 'BPCKQDTLMNRGJXZSFV', $s);
             $s = $first_letter . $s;
             if (strlen($s) < 4) {
                 $s = $s . str_repeat('0', 4 - strlen($s));
             } else {
                 $s = substr($s, 0, 4);
             }
             return new StringBuffer($s);
         }
         return FALSE;
     } else {
         return new StringBuffer(soundex($s));
     }
 }