Find Similar Sounding Words in PHP
Let say a condition where we wanted a utility that finds a matches of words which sounds all same. For example, stupid/stpid/stuuupid/sstuuupiid would all have the same soundex code, S313, Soundex is a phonetic algorithm which computes a soundex value for each english word passed to it. We can get similar sounding words using a function called soundex in php. This feature can be used in spell & document checking.
The first letter of the word becomes the first letter of the Soundex code. Cross out all vowels (A, E, I, O, U, Y), and the letters H and W, that follow the initial letter.If your word has less than three letters left, assign zeroes to those places. Your final Soundex code should be the first letter of the word followed by three numbers (i.e. stupid is coded as S313).
Step 1: The first letter of the word becomes the first letter of the Soundex code.
Step 2: The consonants are replaced with numbers as below:
Step 3: If two adjacent letters have the same number, the second is removed.
Step 4: Add zeros to make up the three numbers if no letters remain.
Description of Function:
soundex — Calculate the soundex key of a string
string soundex ( string $str )
Parameters: $str : input string
Return value: Returns the soundex key as a string.
The following code is an example where we try to find the word 'stupid' from a list of some similar sounding words.
Soudex at Wikipedia
soundex function at php.net
|All times are GMT +5.5. The time now is 21:56.|