PHP metaphone() Function

The metaphone() function calculates the metaphone key of a string.A metaphone key represents how a string sounds if said by an English speaking person.The metaphone() function can be used for spelling applications.

The metaphone() function creates the same key for similar sounding words.The generated metaphone keys vary in length.

string metaphone ( string $str [, int $phonemes = 0 ] )

Calculates the metaphone key of str.

Similar to soundex() metaphone creates the same key for similar sounding words. It's more accurate than soundex() as it knows the basic rules of English pronunciation. The metaphone generated keys are of variable length.

Metaphone was developed by Lawrence Philips . It is described in ["Practical Algorithms for Programmers", Binstock & Rex, Addison Wesley, 1995].

Example -

Example #1 metaphone() basic example

The above example will output something similar to : -

string(7) "PRKRMNK"
string(6) "PRKRMR"

Example #2 Using the phonemes parameter

The above example will output something similar to : -

string(5) "PRKRM"
string(5) "PRKRM"

ParameterDescription
strThe input string.
phonemesThis parameter restricts the returned metaphone key to phonemes characters in length. The default value of 0 means no restriction.

Returns the metaphone key as a string, or FALSE on failure.