64 public function metaphone($string, $sys_language_uid = 0)
67 return $res[
'primary'];
81 $this->secondary =
'';
84 $this->length = strlen($string);
85 $this->last = $this->length - 1;
86 $this->original = $string .
' ';
87 $this->original = strtoupper($this->original);
89 if ($this->
StringAt($this->original, 0, 2, [
'GN',
'KN',
'PN',
'WR',
'PS'])) {
93 if ($this->original[0] ===
'X') {
94 $this->primary .=
'S';
96 $this->secondary .=
'S';
100 while (strlen($this->primary) < 4 || strlen($this->secondary) < 4) {
101 if ($this->current >= $this->length) {
104 switch (substr($this->original, $this->current, 1)) {
116 if ($this->current == 0) {
118 $this->primary .=
'A';
119 $this->secondary .=
'A';
125 $this->primary .=
'P';
126 $this->secondary .=
'P';
127 if (substr($this->original, $this->current + 1, 1) ===
'B') {
134 $this->primary .=
'S';
135 $this->secondary .=
'S';
140 if ($this->current > 1 && !$this->
IsVowel($this->original, $this->current - 2) && $this->
StringAt($this->original, $this->current - 1, 3, [
'ACH']) && (substr($this->original, $this->current + 2, 1) !==
'I' && (substr($this->original, $this->current + 2, 1) !==
'E' || $this->
StringAt($this->original, $this->current - 2, 6, [
'BACHER',
'MACHER'])))) {
141 $this->primary .=
'K';
142 $this->secondary .=
'K';
147 if ($this->current == 0 && $this->
StringAt($this->original, $this->current, 6, [
'CAESAR'])) {
148 $this->primary .=
'S';
149 $this->secondary .=
'S';
154 if ($this->
StringAt($this->original, $this->current, 4, [
'CHIA'])) {
155 $this->primary .=
'K';
156 $this->secondary .=
'K';
160 if ($this->
StringAt($this->original, $this->current, 2, [
'CH'])) {
162 if ($this->current > 0 && $this->
StringAt($this->original, $this->current, 4, [
'CHAE'])) {
163 $this->primary .=
'K';
164 $this->secondary .=
'X';
169 if ($this->current == 0 && ($this->
StringAt($this->original, $this->current + 1, 5, [
'HARAC',
'HARIS']) || $this->
StringAt($this->original, $this->current + 1, 3, [
'HOR',
'HYM',
'HIA',
'HEM'])) && !$this->
StringAt($this->original, 0, 5, [
'CHORE'])) {
170 $this->primary .=
'K';
171 $this->secondary .=
'K';
176 if ($this->
StringAt($this->original, 0, 4, [
'VAN ',
'VON ']) || $this->
StringAt($this->original, 0, 3, [
'SCH']) || $this->
StringAt($this->original, $this->current - 2, 6, [
'ORCHES',
'ARCHIT',
'ORCHID']) || $this->
StringAt($this->original, $this->current + 2, 1, [
'T',
'S']) || ($this->
StringAt($this->original, $this->current - 1, 1, [
'A',
'O',
'U',
'E']) || $this->current == 0) && $this->
StringAt($this->original, $this->current + 2, 1, [
'L',
'R',
'N',
'M',
'B',
'H',
'F',
'V',
'W',
' '])) {
177 $this->primary .=
'K';
178 $this->secondary .=
'K';
180 if ($this->current > 0) {
181 if ($this->
StringAt($this->original, 0, 2, [
'MC'])) {
183 $this->primary .=
'K';
184 $this->secondary .=
'K';
186 $this->primary .=
'X';
187 $this->secondary .=
'K';
190 $this->primary .=
'X';
191 $this->secondary .=
'X';
198 if ($this->
StringAt($this->original, $this->current, 2, [
'CZ']) && !$this->
StringAt(
204 $this->primary .=
'S';
205 $this->secondary .=
'X';
210 if ($this->
StringAt($this->original, $this->current + 1, 3, [
'CIA'])) {
211 $this->primary .=
'X';
212 $this->secondary .=
'X';
217 if ($this->
StringAt($this->original, $this->current, 2, [
'CC']) && !($this->current == 1 && $this->original[0] ===
'M')) {
219 if ($this->
StringAt($this->original, $this->current + 2, 1, [
'I',
'E',
'H']) && !$this->
StringAt(
226 if ($this->current == 1 && substr($this->original, $this->current - 1, 1) ===
'A' || $this->
StringAt($this->original, $this->current - 1, 5, [
'UCCEE',
'UCCES'])) {
227 $this->primary .=
'KS';
228 $this->secondary .=
'KS';
230 $this->primary .=
'X';
231 $this->secondary .=
'X';
237 $this->primary .=
'K';
238 $this->secondary .=
'K';
242 if ($this->
StringAt($this->original, $this->current, 2, [
'CK',
'CG',
'CQ'])) {
243 $this->primary .=
'K';
244 $this->secondary .=
'K';
248 if ($this->
StringAt($this->original, $this->current, 2, [
'CI',
'CE',
'CY'])) {
250 if ($this->
StringAt($this->original, $this->current, 3, [
'CIO',
'CIE',
'CIA'])) {
251 $this->primary .=
'S';
252 $this->secondary .=
'X';
254 $this->primary .=
'S';
255 $this->secondary .=
'S';
261 $this->primary .=
'K';
262 $this->secondary .=
'K';
264 if ($this->
StringAt($this->original, $this->current + 1, 2, [
' C',
' Q',
' G'])) {
267 if ($this->
StringAt($this->original, $this->current + 1, 1, [
'C',
'K',
'Q']) && !$this->
StringAt(
280 if ($this->
StringAt($this->original, $this->current, 2, [
'DG'])) {
281 if ($this->
StringAt($this->original, $this->current + 2, 1, [
'I',
'E',
'Y'])) {
283 $this->primary .=
'J';
284 $this->secondary .=
'J';
289 $this->primary .=
'TK';
290 $this->secondary .=
'TK';
294 if ($this->
StringAt($this->original, $this->current, 2, [
'DT',
'DD'])) {
295 $this->primary .=
'T';
296 $this->secondary .=
'T';
301 $this->primary .=
'T';
302 $this->secondary .=
'T';
306 if (substr($this->original, $this->current + 1, 1) ===
'F') {
311 $this->primary .=
'F';
312 $this->secondary .=
'F';
315 if (substr($this->original, $this->current + 1, 1) ===
'H') {
316 if ($this->current > 0 && !$this->
IsVowel($this->original, $this->current - 1)) {
317 $this->primary .=
'K';
318 $this->secondary .=
'K';
322 if ($this->current < 3) {
324 if ($this->current == 0) {
325 if (substr($this->original, $this->current + 2, 1) ===
'I') {
326 $this->primary .=
'J';
327 $this->secondary .=
'J';
329 $this->primary .=
'K';
330 $this->secondary .=
'K';
337 if ($this->current > 1 && $this->
StringAt($this->original, $this->current - 2, 1, [
'B',
'H',
'D']) || $this->current > 2 && $this->
StringAt($this->original, $this->current - 3, 1, [
'B',
'H',
'D']) || $this->current > 3 && $this->
StringAt($this->original, $this->current - 4, 1, [
'B',
'H'])) {
342 if ($this->current > 2 && substr($this->original, $this->current - 1, 1) ===
'U' && $this->
StringAt($this->original, $this->current - 3, 1, [
'C',
'G',
'L',
'R',
'T'])) {
343 $this->primary .=
'F';
344 $this->secondary .=
'F';
345 } elseif ($this->current > 0 && substr($this->original, $this->current - 1, 1) !==
'I') {
346 $this->primary .=
'K';
347 $this->secondary .=
'K';
352 if (substr($this->original, $this->current + 1, 1) ===
'N') {
353 if ($this->current == 1 && $this->
IsVowel($this->original, 0) && !$this->
SlavoGermanic($this->original)) {
354 $this->primary .=
'KN';
355 $this->secondary .=
'N';
358 if (!$this->
StringAt($this->original, $this->current + 2, 2, [
'EY']) && substr($this->original, $this->current + 1) !==
'Y' && !$this->
SlavoGermanic($this->original)) {
359 $this->primary .=
'N';
360 $this->secondary .=
'KN';
362 $this->primary .=
'KN';
363 $this->secondary .=
'KN';
370 if ($this->
StringAt($this->original, $this->current + 1, 2, [
'LI']) && !$this->
SlavoGermanic($this->original)) {
371 $this->primary .=
'KL';
372 $this->secondary .=
'L';
377 if ($this->current == 0 && (substr($this->original, $this->current + 1, 1) ===
'Y' || $this->
StringAt($this->original, $this->current + 1, 2, [
390 $this->primary .=
'K';
391 $this->secondary .=
'J';
396 if (($this->
StringAt($this->original, $this->current + 1, 2, [
'ER']) || substr($this->original, $this->current + 1, 1) ===
'Y') && !$this->
StringAt($this->original, 0, 6, [
'DANGER',
'RANGER',
'MANGER']) && !$this->
StringAt(
401 ) && !$this->
StringAt($this->original, $this->current - 1, 3, [
'RGY',
'OGY'])) {
402 $this->primary .=
'K';
403 $this->secondary .=
'J';
408 if ($this->
StringAt($this->original, $this->current + 1, 1, [
'E',
'I',
'Y']) || $this->
StringAt($this->original, $this->current - 1, 4, [
'AGGI',
'OGGI'])) {
410 if ($this->
StringAt($this->original, 0, 4, [
'VAN ',
'VON ']) || $this->
StringAt($this->original, 0, 3, [
'SCH']) || $this->
StringAt($this->original, $this->current + 1, 2, [
'ET'])) {
411 $this->primary .=
'K';
412 $this->secondary .=
'K';
415 if ($this->
StringAt($this->original, $this->current + 1, 4, [
'IER '])) {
416 $this->primary .=
'J';
417 $this->secondary .=
'J';
419 $this->primary .=
'J';
420 $this->secondary .=
'K';
426 if (substr($this->original, $this->current + 1, 1) ===
'G') {
431 $this->primary .=
'K';
432 $this->secondary .=
'K';
436 if (($this->current == 0 || $this->
IsVowel($this->original, $this->current - 1)) && $this->
IsVowel($this->original, $this->current + 1)) {
437 $this->primary .=
'H';
438 $this->secondary .=
'H';
446 if ($this->
StringAt($this->original, $this->current, 4, [
'JOSE']) || $this->
StringAt($this->original, 0, 4, [
'SAN '])) {
447 if ($this->current == 0 && substr($this->original, $this->current + 4, 1) ===
' ' || $this->
StringAt($this->original, 0, 4, [
'SAN '])) {
448 $this->primary .=
'H';
449 $this->secondary .=
'H';
451 $this->primary .=
'J';
452 $this->secondary .=
'H';
457 if ($this->current == 0 && !$this->
StringAt($this->original, $this->current, 4, [
'JOSE'])) {
458 $this->primary .=
'J';
460 $this->secondary .=
'A';
463 if ($this->
IsVowel($this->original, $this->current - 1) && !$this->
SlavoGermanic($this->original) && (substr($this->original, $this->current + 1, 1) ===
'A' || substr($this->original, $this->current + 1, 1) ===
'O')) {
464 $this->primary .=
'J';
465 $this->secondary .=
'H';
467 if ($this->current == $this->last) {
468 $this->primary .=
'J';
469 $this->secondary .=
'';
471 if (!$this->
StringAt($this->original, $this->current + 1, 1, [
'L',
'T',
'K',
'S',
'N',
'M',
'B',
'Z']) && !$this->
StringAt(
477 $this->primary .=
'J';
478 $this->secondary .=
'J';
483 if (substr($this->original, $this->current + 1, 1) ===
'J') {
491 if (substr($this->original, $this->current + 1, 1) ===
'K') {
496 $this->primary .=
'K';
497 $this->secondary .=
'K';
500 if (substr($this->original, $this->current + 1, 1) ===
'L') {
502 if ($this->current == $this->length - 3 && $this->
StringAt($this->original, $this->current - 1, 4, [
'ILLO',
'ILLA',
'ALLE']) || ($this->
StringAt($this->original, $this->last - 1, 2, [
'AS',
'OS']) || $this->
StringAt($this->original, $this->last, 1, [
'A',
'O'])) && $this->
StringAt($this->original, $this->current - 1, 4, [
'ALLE'])) {
503 $this->primary .=
'L';
504 $this->secondary .=
'';
512 $this->primary .=
'L';
513 $this->secondary .=
'L';
516 if ($this->
StringAt($this->original, $this->current - 1, 3, [
'UMB']) && ($this->current + 1 == $this->last || $this->
StringAt($this->original, $this->current + 2, 2, [
'ER'])) || substr($this->original, $this->current + 1, 1) ===
'M') {
521 $this->primary .=
'M';
522 $this->secondary .=
'M';
525 if (substr($this->original, $this->current + 1, 1) ===
'N') {
530 $this->primary .=
'N';
531 $this->secondary .=
'N';
535 $this->primary .=
'N';
536 $this->secondary .=
'N';
539 if (substr($this->original, $this->current + 1, 1) ===
'H') {
541 $this->primary .=
'F';
542 $this->secondary .=
'F';
546 if ($this->
StringAt($this->original, $this->current + 1, 1, [
'P',
'B'])) {
551 $this->primary .=
'P';
552 $this->secondary .=
'P';
555 if (substr($this->original, $this->current + 1, 1) ===
'Q') {
560 $this->primary .=
'K';
561 $this->secondary .=
'K';
565 if ($this->current == $this->last && !$this->
SlavoGermanic($this->original) && $this->
StringAt($this->original, $this->current - 2, 2, [
'IE']) && !$this->
StringAt(
571 $this->primary .=
'';
572 $this->secondary .=
'R';
574 $this->primary .=
'R';
575 $this->secondary .=
'R';
577 if (substr($this->original, $this->current + 1, 1) ===
'R') {
585 if ($this->
StringAt($this->original, $this->current - 1, 3, [
'ISL',
'YSL'])) {
590 if ($this->current == 0 && $this->
StringAt($this->original, $this->current, 5, [
'SUGAR'])) {
591 $this->primary .=
'X';
592 $this->secondary .=
'S';
596 if ($this->
StringAt($this->original, $this->current, 2, [
'SH'])) {
598 if ($this->
StringAt($this->original, $this->current + 1, 4, [
'HEIM',
'HOEK',
'HOLM',
'HOLZ'])) {
599 $this->primary .=
'S';
600 $this->secondary .=
'S';
602 $this->primary .=
'X';
603 $this->secondary .=
'X';
609 if ($this->
StringAt($this->original, $this->current, 3, [
'SIO',
'SIA']) || $this->
StringAt($this->original, $this->current, 4, [
'SIAN'])) {
611 $this->primary .=
'S';
612 $this->secondary .=
'X';
614 $this->primary .=
'S';
615 $this->secondary .=
'S';
622 if ($this->current == 0 && $this->
StringAt($this->original, $this->current + 1, 1, [
'M',
'N',
'L',
'W']) || $this->
StringAt($this->original, $this->current + 1, 1, [
'Z'])) {
623 $this->primary .=
'S';
624 $this->secondary .=
'X';
625 if ($this->
StringAt($this->original, $this->current + 1, 1, [
'Z'])) {
632 if ($this->
StringAt($this->original, $this->current, 2, [
'SC'])) {
634 if (substr($this->original, $this->current + 2, 1) ===
'H') {
636 if ($this->
StringAt($this->original, $this->current + 3, 2, [
'OO',
'ER',
'EN',
'UY',
'ED',
'EM'])) {
638 if ($this->
StringAt($this->original, $this->current + 3, 2, [
'ER',
'EN'])) {
639 $this->primary .=
'X';
640 $this->secondary .=
'SK';
642 $this->primary .=
'SK';
643 $this->secondary .=
'SK';
648 if ($this->current == 0 && !$this->
IsVowel($this->original, 3) && substr($this->original, $this->current + 3, 1) !==
'W') {
649 $this->primary .=
'X';
650 $this->secondary .=
'S';
652 $this->primary .=
'X';
653 $this->secondary .=
'X';
658 if ($this->
StringAt($this->original, $this->current + 2, 1, [
'I',
'E',
'Y'])) {
659 $this->primary .=
'S';
660 $this->secondary .=
'S';
665 $this->primary .=
'SK';
666 $this->secondary .=
'SK';
671 if ($this->current == $this->last && $this->
StringAt($this->original, $this->current - 2, 2, [
'AI',
'OI'])) {
672 $this->primary .=
'';
673 $this->secondary .=
'S';
675 $this->primary .=
'S';
676 $this->secondary .=
'S';
678 if ($this->
StringAt($this->original, $this->current + 1, 1, [
'S',
'Z'])) {
685 if ($this->
StringAt($this->original, $this->current, 4, [
'TION'])) {
686 $this->primary .=
'X';
687 $this->secondary .=
'X';
691 if ($this->
StringAt($this->original, $this->current, 3, [
'TIA',
'TCH'])) {
692 $this->primary .=
'X';
693 $this->secondary .=
'X';
697 if ($this->
StringAt($this->original, $this->current, 2, [
'TH']) || $this->
StringAt($this->original, $this->current, 3, [
'TTH'])) {
699 if ($this->
StringAt($this->original, $this->current + 2, 2, [
'OM',
'AM']) || $this->
StringAt($this->original, 0, 4, [
'VAN ',
'VON ']) || $this->
StringAt($this->original, 0, 3, [
'SCH'])) {
700 $this->primary .=
'T';
701 $this->secondary .=
'T';
703 $this->primary .=
'0';
704 $this->secondary .=
'T';
709 if ($this->
StringAt($this->original, $this->current + 1, 1, [
'T',
'D'])) {
714 $this->primary .=
'T';
715 $this->secondary .=
'T';
718 if (substr($this->original, $this->current + 1, 1) ===
'V') {
723 $this->primary .=
'F';
724 $this->secondary .=
'F';
728 if ($this->
StringAt($this->original, $this->current, 2, [
'WR'])) {
729 $this->primary .=
'R';
730 $this->secondary .=
'R';
734 if ($this->current == 0 && ($this->
IsVowel($this->original, $this->current + 1) || $this->
StringAt($this->original, $this->current, 2, [
'WH']))) {
736 if ($this->
IsVowel($this->original, $this->current + 1)) {
737 $this->primary .=
'A';
738 $this->secondary .=
'F';
741 $this->primary .=
'A';
742 $this->secondary .=
'A';
746 if ($this->current == $this->last && $this->
IsVowel($this->original, $this->current - 1) || $this->
StringAt($this->original, $this->current - 1, 5, [
'EWSKI',
'EWSKY',
'OWSKI',
'OWSKY']) || $this->
StringAt($this->original, 0, 3, [
'SCH'])) {
747 $this->primary .=
'';
748 $this->secondary .=
'F';
753 if ($this->
StringAt($this->original, $this->current, 4, [
'WICZ',
'WITZ'])) {
754 $this->primary .=
'TS';
755 $this->secondary .=
'FX';
764 if (!($this->current == $this->last && ($this->
StringAt($this->original, $this->current - 3, 3, [
'IAU',
'EAU']) || $this->
StringAt($this->original, $this->current - 2, 2, [
'AU',
'OU'])))) {
765 $this->primary .=
'KS';
766 $this->secondary .=
'KS';
768 if ($this->
StringAt($this->original, $this->current + 1, 1, [
'C',
'X'])) {
776 if (substr($this->original, $this->current + 1, 1) ===
'H') {
777 $this->primary .=
'J';
778 $this->secondary .=
'J';
782 if ($this->
StringAt($this->original, $this->current + 1, 2, [
'ZO',
'ZI',
'ZA']) || $this->
SlavoGermanic($this->original) && ($this->current > 0 && substr($this->original, $this->current - 1, 1) !==
'T')) {
783 $this->primary .=
'S';
784 $this->secondary .=
'TS';
786 $this->primary .=
'S';
787 $this->secondary .=
'S';
789 if (substr($this->original, $this->current + 1, 1) ===
'Z') {
800 $this->primary = substr($this->primary, 0, 4);
801 $this->secondary = substr($this->secondary, 0, 4);
820 if ($start < 0 || $start >= strlen($string)) {
823 $listCount = count($list);
824 for ($i = 0; $i < $listCount; $i++) {
825 if ($list[$i] == substr($string, $start,
$length)) {
839 public function IsVowel($string, $pos)
841 return preg_match(
'/[AEIOUY]/', substr($string, $pos, 1));
852 return preg_match(
'/W|K|CZ|WITZ/', $string);