60 public function metaphone($string, $sys_language_uid = 0) {
63 return $res[
'primary'];
73 $this->secondary =
'';
76 $this->length = strlen($string);
77 $this->last = $this->length - 1;
78 $this->original = $string .
' ';
79 $this->original = strtoupper($this->original);
81 if ($this->
StringAt($this->original, 0, 2, array(
'GN',
'KN',
'PN',
'WR',
'PS'))) {
85 if ($this->original[0] ===
'X') {
86 $this->primary .=
'S';
88 $this->secondary .=
'S';
92 while (strlen($this->primary) < 4 || strlen($this->secondary < 4)) {
93 if ($this->current >= $this->length) {
96 switch (substr($this->original, $this->current, 1)) {
108 if ($this->current == 0) {
110 $this->primary .=
'A';
111 $this->secondary .=
'A';
117 $this->primary .=
'P';
118 $this->secondary .=
'P';
119 if (substr($this->original, $this->current + 1, 1) ==
'B') {
126 $this->primary .=
'S';
127 $this->secondary .=
'S';
132 if ($this->current > 1 && !$this->
IsVowel($this->original, ($this->current - 2)) && $this->
StringAt($this->original, $this->current - 1, 3, array(
'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, array(
'BACHER',
'MACHER'))))) {
133 $this->primary .=
'K';
134 $this->secondary .=
'K';
139 if ($this->current == 0 && $this->
StringAt($this->original, $this->current, 6, array(
'CAESAR'))) {
140 $this->primary .=
'S';
141 $this->secondary .=
'S';
146 if ($this->
StringAt($this->original, $this->current, 4, array(
'CHIA'))) {
147 $this->primary .=
'K';
148 $this->secondary .=
'K';
152 if ($this->
StringAt($this->original, $this->current, 2, array(
'CH'))) {
154 if ($this->current > 0 && $this->
StringAt($this->original, $this->current, 4, array(
'CHAE'))) {
155 $this->primary .=
'K';
156 $this->secondary .=
'X';
161 if ($this->current == 0 && ($this->
StringAt($this->original, $this->current + 1, 5, array(
'HARAC',
'HARIS')) || $this->
StringAt($this->original, $this->current + 1, 3, array(
'HOR',
'HYM',
'HIA',
'HEM'))) && !$this->
StringAt($this->original, 0, 5, array(
'CHORE'))) {
162 $this->primary .=
'K';
163 $this->secondary .=
'K';
168 if ($this->
StringAt($this->original, 0, 4, array(
'VAN ',
'VON ')) || $this->
StringAt($this->original, 0, 3, array(
'SCH')) || $this->
StringAt($this->original, $this->current - 2, 6, array(
'ORCHES',
'ARCHIT',
'ORCHID')) || $this->
StringAt($this->original, $this->current + 2, 1, array(
'T',
'S')) || ($this->
StringAt($this->original, $this->current - 1, 1, array(
'A',
'O',
'U',
'E')) || $this->current == 0) && $this->
StringAt($this->original, $this->current + 2, 1, array(
'L',
'R',
'N',
'M',
'B',
'H',
'F',
'V',
'W',
' '))) {
169 $this->primary .=
'K';
170 $this->secondary .=
'K';
172 if ($this->current > 0) {
173 if ($this->
StringAt($this->original, 0, 2, array(
'MC'))) {
175 $this->primary .=
'K';
176 $this->secondary .=
'K';
178 $this->primary .=
'X';
179 $this->secondary .=
'K';
182 $this->primary .=
'X';
183 $this->secondary .=
'X';
190 if ($this->
StringAt($this->original, $this->current, 2, array(
'CZ')) && !$this->
StringAt($this->original, ($this->current - 2), 4, array(
'WICZ'))) {
191 $this->primary .=
'S';
192 $this->secondary .=
'X';
197 if ($this->
StringAt($this->original, $this->current + 1, 3, array(
'CIA'))) {
198 $this->primary .=
'X';
199 $this->secondary .=
'X';
204 if ($this->
StringAt($this->original, $this->current, 2, array(
'CC')) && !($this->current == 1 && $this->original[0] ===
'M')) {
206 if ($this->
StringAt($this->original, $this->current + 2, 1, array(
'I',
'E',
'H')) && !$this->
StringAt($this->original, ($this->current + 2), 2, array(
'HU'))) {
208 if ($this->current == 1 && substr($this->original, $this->current - 1, 1) ==
'A' || $this->
StringAt($this->original, $this->current - 1, 5, array(
'UCCEE',
'UCCES'))) {
209 $this->primary .=
'KS';
210 $this->secondary .=
'KS';
212 $this->primary .=
'X';
213 $this->secondary .=
'X';
219 $this->primary .=
'K';
220 $this->secondary .=
'K';
225 if ($this->
StringAt($this->original, $this->current, 2, array(
'CK',
'CG',
'CQ'))) {
226 $this->primary .=
'K';
227 $this->secondary .=
'K';
231 if ($this->
StringAt($this->original, $this->current, 2, array(
'CI',
'CE',
'CY'))) {
233 if ($this->
StringAt($this->original, $this->current, 3, array(
'CIO',
'CIE',
'CIA'))) {
234 $this->primary .=
'S';
235 $this->secondary .=
'X';
237 $this->primary .=
'S';
238 $this->secondary .=
'S';
244 $this->primary .=
'K';
245 $this->secondary .=
'K';
247 if ($this->
StringAt($this->original, $this->current + 1, 2, array(
' C',
' Q',
' G'))) {
250 if ($this->
StringAt($this->original, $this->current + 1, 1, array(
'C',
'K',
'Q')) && !$this->
StringAt($this->original, ($this->current + 1), 2, array(
'CE',
'CI'))) {
258 if ($this->
StringAt($this->original, $this->current, 2, array(
'DG'))) {
259 if ($this->
StringAt($this->original, $this->current + 2, 1, array(
'I',
'E',
'Y'))) {
261 $this->primary .=
'J';
262 $this->secondary .=
'J';
267 $this->primary .=
'TK';
268 $this->secondary .=
'TK';
273 if ($this->
StringAt($this->original, $this->current, 2, array(
'DT',
'DD'))) {
274 $this->primary .=
'T';
275 $this->secondary .=
'T';
280 $this->primary .=
'T';
281 $this->secondary .=
'T';
285 if (substr($this->original, $this->current + 1, 1) ==
'F') {
290 $this->primary .=
'F';
291 $this->secondary .=
'F';
294 if (substr($this->original, $this->current + 1, 1) ==
'H') {
295 if ($this->current > 0 && !$this->
IsVowel($this->original, ($this->current - 1))) {
296 $this->primary .=
'K';
297 $this->secondary .=
'K';
301 if ($this->current < 3) {
303 if ($this->current == 0) {
304 if (substr($this->original, $this->current + 2, 1) ==
'I') {
305 $this->primary .=
'J';
306 $this->secondary .=
'J';
308 $this->primary .=
'K';
309 $this->secondary .=
'K';
316 if ($this->current > 1 && $this->
StringAt($this->original, $this->current - 2, 1, array(
'B',
'H',
'D')) || $this->current > 2 && $this->
StringAt($this->original, $this->current - 3, 1, array(
'B',
'H',
'D')) || $this->current > 3 && $this->
StringAt($this->original, $this->current - 4, 1, array(
'B',
'H'))) {
321 if ($this->current > 2 && substr($this->original, $this->current - 1, 1) ==
'U' && $this->
StringAt($this->original, $this->current - 3, 1, array(
'C',
'G',
'L',
'R',
'T'))) {
322 $this->primary .=
'F';
323 $this->secondary .=
'F';
324 } elseif ($this->current > 0 && substr($this->original, $this->current - 1, 1) !=
'I') {
325 $this->primary .=
'K';
326 $this->secondary .=
'K';
332 if (substr($this->original, $this->current + 1, 1) ==
'N') {
333 if ($this->current == 1 && $this->
IsVowel($this->original, 0) && !$this->
SlavoGermanic($this->original)) {
334 $this->primary .=
'KN';
335 $this->secondary .=
'N';
338 if (!$this->
StringAt($this->original, ($this->current + 2), 2, array(
'EY')) && substr($this->original, $this->current + 1) !=
'Y' && !$this->
SlavoGermanic($this->original)) {
339 $this->primary .=
'N';
340 $this->secondary .=
'KN';
342 $this->primary .=
'KN';
343 $this->secondary .=
'KN';
350 if ($this->
StringAt($this->original, $this->current + 1, 2, array(
'LI')) && !$this->
SlavoGermanic($this->original)) {
351 $this->primary .=
'KL';
352 $this->secondary .=
'L';
357 if ($this->current == 0 && (substr($this->original, $this->current + 1, 1) ==
'Y' || $this->
StringAt($this->original, $this->current + 1, 2, array(
370 $this->primary .=
'K';
371 $this->secondary .=
'J';
376 if (($this->
StringAt($this->original, $this->current + 1, 2, array(
'ER')) || substr($this->original, $this->current + 1, 1) ==
'Y') && !$this->
StringAt($this->original, 0, 6, array(
'DANGER',
'RANGER',
'MANGER')) && !$this->
StringAt($this->original, ($this->current - 1), 1, array(
'E',
'I')) && !$this->
StringAt($this->original, ($this->current - 1), 3, array(
'RGY',
'OGY'))) {
377 $this->primary .=
'K';
378 $this->secondary .=
'J';
383 if ($this->
StringAt($this->original, $this->current + 1, 1, array(
'E',
'I',
'Y')) || $this->
StringAt($this->original, $this->current - 1, 4, array(
'AGGI',
'OGGI'))) {
385 if ($this->
StringAt($this->original, 0, 4, array(
'VAN ',
'VON ')) || $this->
StringAt($this->original, 0, 3, array(
'SCH')) || $this->
StringAt($this->original, $this->current + 1, 2, array(
'ET'))) {
386 $this->primary .=
'K';
387 $this->secondary .=
'K';
390 if ($this->
StringAt($this->original, $this->current + 1, 4, array(
'IER '))) {
391 $this->primary .=
'J';
392 $this->secondary .=
'J';
394 $this->primary .=
'J';
395 $this->secondary .=
'K';
401 if (substr($this->original, $this->current + 1, 1) ==
'G') {
406 $this->primary .=
'K';
407 $this->secondary .=
'K';
411 if (($this->current == 0 || $this->
IsVowel($this->original, $this->current - 1)) && $this->
IsVowel($this->original, $this->current + 1)) {
412 $this->primary .=
'H';
413 $this->secondary .=
'H';
421 if ($this->
StringAt($this->original, $this->current, 4, array(
'JOSE')) || $this->
StringAt($this->original, 0, 4, array(
'SAN '))) {
422 if ($this->current == 0 && substr($this->original, $this->current + 4, 1) ==
' ' || $this->
StringAt($this->original, 0, 4, array(
'SAN '))) {
423 $this->primary .=
'H';
424 $this->secondary .=
'H';
426 $this->primary .=
'J';
427 $this->secondary .=
'H';
432 if ($this->current == 0 && !$this->
StringAt($this->original, $this->current, 4, array(
'JOSE'))) {
433 $this->primary .=
'J';
435 $this->secondary .=
'A';
438 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')) {
439 $this->primary .=
'J';
440 $this->secondary .=
'H';
442 if ($this->current == $this->last) {
443 $this->primary .=
'J';
444 $this->secondary .=
'';
446 if (!$this->
StringAt($this->original, ($this->current + 1), 1, array(
'L',
'T',
'K',
'S',
'N',
'M',
'B',
'Z')) && !$this->
StringAt($this->original, ($this->current - 1), 1, array(
'S',
'K',
'L'))) {
447 $this->primary .=
'J';
448 $this->secondary .=
'J';
453 if (substr($this->original, $this->current + 1, 1) ==
'J') {
461 if (substr($this->original, $this->current + 1, 1) ==
'K') {
466 $this->primary .=
'K';
467 $this->secondary .=
'K';
470 if (substr($this->original, $this->current + 1, 1) ==
'L') {
472 if ($this->current == $this->length - 3 && $this->
StringAt($this->original, $this->current - 1, 4, array(
'ILLO',
'ILLA',
'ALLE')) || ($this->
StringAt($this->original, $this->last - 1, 2, array(
'AS',
'OS')) || $this->
StringAt($this->original, $this->last, 1, array(
'A',
'O'))) && $this->
StringAt($this->original, $this->current - 1, 4, array(
'ALLE'))) {
473 $this->primary .=
'L';
474 $this->secondary .=
'';
482 $this->primary .=
'L';
483 $this->secondary .=
'L';
486 if ($this->
StringAt($this->original, $this->current - 1, 3, array(
'UMB')) && ($this->current + 1 == $this->last || $this->
StringAt($this->original, $this->current + 2, 2, array(
'ER'))) || substr($this->original, $this->current + 1, 1) ==
'M') {
491 $this->primary .=
'M';
492 $this->secondary .=
'M';
495 if (substr($this->original, $this->current + 1, 1) ==
'N') {
500 $this->primary .=
'N';
501 $this->secondary .=
'N';
505 $this->primary .=
'N';
506 $this->secondary .=
'N';
509 if (substr($this->original, $this->current + 1, 1) ==
'H') {
511 $this->primary .=
'F';
512 $this->secondary .=
'F';
516 if ($this->
StringAt($this->original, $this->current + 1, 1, array(
'P',
'B'))) {
521 $this->primary .=
'P';
522 $this->secondary .=
'P';
525 if (substr($this->original, $this->current + 1, 1) ==
'Q') {
530 $this->primary .=
'K';
531 $this->secondary .=
'K';
535 if ($this->current == $this->last && !$this->
SlavoGermanic($this->original) && $this->
StringAt($this->original, $this->current - 2, 2, array(
'IE')) && !$this->
StringAt($this->original, ($this->current - 4), 2, array(
'ME',
'MA'))) {
536 $this->primary .=
'';
537 $this->secondary .=
'R';
539 $this->primary .=
'R';
540 $this->secondary .=
'R';
542 if (substr($this->original, $this->current + 1, 1) ==
'R') {
550 if ($this->
StringAt($this->original, $this->current - 1, 3, array(
'ISL',
'YSL'))) {
555 if ($this->current == 0 && $this->
StringAt($this->original, $this->current, 5, array(
'SUGAR'))) {
556 $this->primary .=
'X';
557 $this->secondary .=
'S';
561 if ($this->
StringAt($this->original, $this->current, 2, array(
'SH'))) {
563 if ($this->
StringAt($this->original, $this->current + 1, 4, array(
'HEIM',
'HOEK',
'HOLM',
'HOLZ'))) {
564 $this->primary .=
'S';
565 $this->secondary .=
'S';
567 $this->primary .=
'X';
568 $this->secondary .=
'X';
574 if ($this->
StringAt($this->original, $this->current, 3, array(
'SIO',
'SIA')) || $this->
StringAt($this->original, $this->current, 4, array(
'SIAN'))) {
576 $this->primary .=
'S';
577 $this->secondary .=
'X';
579 $this->primary .=
'S';
580 $this->secondary .=
'S';
587 if ($this->current == 0 && $this->
StringAt($this->original, $this->current + 1, 1, array(
'M',
'N',
'L',
'W')) || $this->
StringAt($this->original, $this->current + 1, 1, array(
'Z'))) {
588 $this->primary .=
'S';
589 $this->secondary .=
'X';
590 if ($this->
StringAt($this->original, $this->current + 1, 1, array(
'Z'))) {
597 if ($this->
StringAt($this->original, $this->current, 2, array(
'SC'))) {
599 if (substr($this->original, $this->current + 2, 1) ==
'H') {
601 if ($this->
StringAt($this->original, $this->current + 3, 2, array(
'OO',
'ER',
'EN',
'UY',
'ED',
'EM'))) {
603 if ($this->
StringAt($this->original, $this->current + 3, 2, array(
'ER',
'EN'))) {
604 $this->primary .=
'X';
605 $this->secondary .=
'SK';
607 $this->primary .=
'SK';
608 $this->secondary .=
'SK';
613 if ($this->current == 0 && !$this->
IsVowel($this->original, 3) && substr($this->original, $this->current + 3, 1) !=
'W') {
614 $this->primary .=
'X';
615 $this->secondary .=
'S';
617 $this->primary .=
'X';
618 $this->secondary .=
'X';
624 if ($this->
StringAt($this->original, $this->current + 2, 1, array(
'I',
'E',
'Y'))) {
625 $this->primary .=
'S';
626 $this->secondary .=
'S';
631 $this->primary .=
'SK';
632 $this->secondary .=
'SK';
637 if ($this->current == $this->last && $this->
StringAt($this->original, $this->current - 2, 2, array(
'AI',
'OI'))) {
638 $this->primary .=
'';
639 $this->secondary .=
'S';
641 $this->primary .=
'S';
642 $this->secondary .=
'S';
644 if ($this->
StringAt($this->original, $this->current + 1, 1, array(
'S',
'Z'))) {
651 if ($this->
StringAt($this->original, $this->current, 4, array(
'TION'))) {
652 $this->primary .=
'X';
653 $this->secondary .=
'X';
657 if ($this->
StringAt($this->original, $this->current, 3, array(
'TIA',
'TCH'))) {
658 $this->primary .=
'X';
659 $this->secondary .=
'X';
663 if ($this->
StringAt($this->original, $this->current, 2, array(
'TH')) || $this->
StringAt($this->original, $this->current, 3, array(
'TTH'))) {
665 if ($this->
StringAt($this->original, $this->current + 2, 2, array(
'OM',
'AM')) || $this->
StringAt($this->original, 0, 4, array(
'VAN ',
'VON ')) || $this->
StringAt($this->original, 0, 3, array(
'SCH'))) {
666 $this->primary .=
'T';
667 $this->secondary .=
'T';
669 $this->primary .=
'0';
670 $this->secondary .=
'T';
675 if ($this->
StringAt($this->original, $this->current + 1, 1, array(
'T',
'D'))) {
680 $this->primary .=
'T';
681 $this->secondary .=
'T';
684 if (substr($this->original, $this->current + 1, 1) ==
'V') {
689 $this->primary .=
'F';
690 $this->secondary .=
'F';
694 if ($this->
StringAt($this->original, $this->current, 2, array(
'WR'))) {
695 $this->primary .=
'R';
696 $this->secondary .=
'R';
700 if ($this->current == 0 && ($this->
IsVowel($this->original, $this->current + 1) || $this->
StringAt($this->original, $this->current, 2, array(
'WH')))) {
702 if ($this->
IsVowel($this->original, $this->current + 1)) {
703 $this->primary .=
'A';
704 $this->secondary .=
'F';
707 $this->primary .=
'A';
708 $this->secondary .=
'A';
712 if ($this->current == $this->last && $this->
IsVowel($this->original, $this->current - 1) || $this->
StringAt($this->original, $this->current - 1, 5, array(
'EWSKI',
'EWSKY',
'OWSKI',
'OWSKY')) || $this->
StringAt($this->original, 0, 3, array(
'SCH'))) {
713 $this->primary .=
'';
714 $this->secondary .=
'F';
719 if ($this->
StringAt($this->original, $this->current, 4, array(
'WICZ',
'WITZ'))) {
720 $this->primary .=
'TS';
721 $this->secondary .=
'FX';
730 if (!($this->current == $this->last && ($this->
StringAt($this->original, $this->current - 3, 3, array(
'IAU',
'EAU')) || $this->
StringAt($this->original, $this->current - 2, 2, array(
'AU',
'OU'))))) {
731 $this->primary .=
'KS';
732 $this->secondary .=
'KS';
734 if ($this->
StringAt($this->original, $this->current + 1, 1, array(
'C',
'X'))) {
742 if (substr($this->original, $this->current + 1, 1) ==
'H') {
743 $this->primary .=
'J';
744 $this->secondary .=
'J';
747 } elseif ($this->
StringAt($this->original, $this->current + 1, 2, array(
'ZO',
'ZI',
'ZA')) || $this->
SlavoGermanic($this->original) && ($this->current > 0 && substr($this->original, $this->current - 1, 1) !=
'T')) {
748 $this->primary .=
'S';
749 $this->secondary .=
'TS';
751 $this->primary .=
'S';
752 $this->secondary .=
'S';
754 if (substr($this->original, $this->current + 1, 1) ==
'Z') {
765 $this->primary = substr($this->primary, 0, 4);
766 $this->secondary = substr($this->secondary, 0, 4);
778 if ($start < 0 || $start >= strlen($string)) {
781 $listCount = count($list);
782 for ($i = 0; $i < $listCount; $i++) {
783 if ($list[$i] == substr($string, $start,
$length)) {
799 return preg_match(
'/[AEIOUY]/', substr($string, $pos, 1));
810 return preg_match(
'/W|K|CZ|WITZ/', $string);
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren't numeric.