The metaphone Function
The metaphone function returns the metaphone of a string - a phonetic key that allows comparing words by their sound. The first parameter is the string to process, and the second (optional) one is the maximum length of the returned metaphone.
Syntax
metaphone(string, [phonemes]);
Example
Let's calculate the metaphone for the word "programming":
<?php
echo metaphone('programming');
?>
Code execution result:
'PRKRMNK'
Example
Let's compare metaphones for words that sound similar:
<?php
$res1 = metaphone('write');
$res2 = metaphone('right');
var_dump($res1 === $res2);
?>
Code execution result:
true
Example
Let's limit the metaphone length to 4 characters:
<?php
echo metaphone('international', 4);
?>
Code execution result:
'ANTR'
See Also
-
the
soundexfunction,
which calculates the soundex-key of a string -
the
levenshteinfunction,
which calculates the distance between strings