5

Metaphone and Soundex are phonetic algorithms for indexing strings by their English pronunciation.

Have you ever used functions metaphone() or soundex() that are present in the standard PHP library?

What for? What are real-life usages of these functions?

unor
  • 92,415
  • 26
  • 211
  • 360
Tom Pažourek
  • 9,582
  • 8
  • 66
  • 107

2 Answers2

7

More generally, soundex and metaphone can be used to find strings that sound similar when pronounced out loud.

This can be used beyond situations where you're just trying to find a "correct" spelling. It might be used, for example, to help spot an error like incorrect usage of a correctly-spelled word that sounds like the right one.

Another attractive use is to try and find the correct name. When I tell someone my name is "Nicholas", there are at least two "alternative" spellings I see them try to use a lot: Nicolas and Nikolas. When they type it in and it doesn't find me in the database, soundex or metaphone might be used to say "There's no Nicolas Knight, but there is a Nicholas Knight".

The degree to which these algorithms actually work, however, is somewhat debatable. They occasionally come up with rather strange results.

Nicholas Knight
  • 15,774
  • 5
  • 45
  • 57
  • One possible real life example of this is Facebook which could very possibly use `soundex()` or `metaphone()` (or equivalent functions) to assist in searching for names because as you mentioned people often search for people based only on the sound of their name. – Chaim Nov 02 '11 at 19:47
2

You could use these when performing a spell-check. You could then easily spot that e.g. 'phorensics' is a good match for 'forensics'.

Will A
  • 24,780
  • 5
  • 50
  • 61
  • That happens to be a bad example for `soundex`, because the leading letter is always the first letter of the word, so `phorensics` is `P652` and `forensics` is `F652` – Michael Mrozek Jul 10 '10 at 17:32
  • D'oh. :) Good call - which leads me to telefone / telephone (which is probably another bad example depending on which language you speak!). How does metaphone handle my dodgy example? – Will A Jul 10 '10 at 17:50
  • 4
    `Phorensics` and `forensics` both return `FRNSKS` using `metaphone`. – Sam Mar 16 '11 at 12:15