Lesser known PHP functions –metaphone
Continuing my Lesser Known PHP Functions series, today’s function is metaphone(). This function is pretty interesting and I had no idea it existed in PHP. However, Metaphone is a phonetic algorithm and it’s purpose is to index words by their English pronunciation. Similar sounding words share the same keys.
If we compare two words such as ‘know’ and ‘now’, their metaphone key will be ‘N’. We can prove this with the following example:
$key_one = metaphone('now');
$key_two = metaphone('know');
if ( $key_one == $key_two ) {
echo 'Keys are matching!';
}
else {
echo 'Keys are NOT matching!';
}
print "<br />Key One: $key_one." // Prints N
print "<br />Key Two: $key_two." // Prints N
Feel free to compare words here: http://sandbox.unemployeddeveloper.com/metaphone.php
With this code we should see a result that tells us that the ‘Keys are matching!’ and also it will return the metaphone() key for both words. This method can be used for spell checkers, however their is a more advanced version available as a PHP class and more, called double metaphone. I would encourage you to look up those if you are looking to utilize this method.
If you like this article, please use the buttons below to share it or leave me a comment and let me know your thoughts – Shawn








![Validate my RSS feed [Valid RSS]](http://www.unemployeddeveloper.com/wp-content/themes/ud2/images/valid-rss.png)
[...] This post was mentioned on Twitter by mooontes, Unemployed Developer. Unemployed Developer said: Unemployed Developer: Lesser known PHP functions –metaphone http://bit.ly/69WImv [...]
I’ve used metaphone() for years to help in searches by adding the metaphone value to the DB. If someone is searcing for “Azov”, and they type in “Asov”, it still finds a row.