PHP.nl

metaphone

metaphone

Calculate the metaphone key of a string

string **metaphone** string $string int $max_phonemes

Calculates the metaphone key of . string

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

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

stringThe input string.

max_phonemes This parameter restricts the returned metaphone key to in length. However, the resulting phonemes are always transcribed completely, so the resulting string length may be slightly longer than . The default value of means no restriction. max_phonemescharactersmax_phonemes``0

Returns the metaphone key as a string.

Voorbeeld: basic example

<?php
var_dump(metaphone('programming'));
var_dump(metaphone('programmer'));
?>
string(7) "PRKRMNK"
string(6) "PRKRMR"

Voorbeeld: Using the parameter

<?php
var_dump(metaphone('programming', 5));
var_dump(metaphone('programmer', 5));
?>
string(5) "PRKRM"
string(5) "PRKRM"

Voorbeeld: Using the parameter

 In this example,  is advised to produce a string
 of five characters, but that would require to split the final phoneme
 ( is supposed to be transcribed to ),
 so the function returns a string with six characters.
`metaphone``'x'``'KS'`
<?php
var_dump(metaphone('Asterix', 5));
?>
string(6) "ASTRKS"

levenshtein``similar_text``soundex