CancelImage Upload

Comparing words that sound similar for more efficient search engine like functions

It can happen to anyone. You are looking for one search term, but instead of spelling it correctly you use a word that sounds similar, but is spelt slightly different. For instance you might be searching for the word "Weather" but have accidentally typed the word "Whether".

Now a really efficient search engine should in this case offer an alternative "Did you mean to search for Weather" link. It is probably one of the most appreciated features on Google for instance.

So, how to compare words that sound alike? As per usual the creators of PHP have a pre built function to provide a solution:


Soundex() simply returns a four digit code that by itself does not mean much to the naked eye, but when you happen to compare the code produced by two similar sounding words you will notice a comparison:


echo soundex("Weather");

echo "<br>";

echo soundex("Whether");


As you will see as a result of the function soundex(), both of these words will output the same code, W360, allowing for a pretty good comparison between the two words.

You may now be saying there are various string comparison functions that can perform a similar task. This is not the case. While string comparison functions look at spelling to compare strings, soundex() only takes the way words sound into account. The spelling of both words, although producing the same sound, could be as different as night and day, making soundex() a valuable PHP function.

Want to leave a comment?

No problem. Just enter your email and password below.

register | home | reminder

myDesignTool Networking •