Soundex

Shows how to use the soundex() function to test if words sounds similar.

$word2find = 'stupid';
 
$words = array(
    'stupid',
    'stu and pid',
    'hello',
    'foobar',
    'stpid',
    'supid',
    'stuuupid',
    'sstuuupiiid',
);
 
while(list($id, $str) = each($words)){
 
    $soundex_code = soundex($str);
 
    if (soundex($word2find) == $soundex_code){
        print '"' . $word2find . '" sounds like ' . $str;
    }
    else {
        print '"' . $word2find . '" sounds not like ' . $str;
    }
 
    print "\n";
}
 
/*
result:
 
"stupid" sounds like stupid
"stupid" sounds not like stu and pid
"stupid" sounds not like hello
"stupid" sounds not like foobar
"stupid" sounds like stpid
"stupid" sounds not like supid
"stupid" sounds like stuuupid
"stupid" sounds like sstuuupiiid
*/
Snippet Details




Sorry folks, comments have been deactivated for now due to the large amount of spam.

Please try to post your questions or problems on a related programming board, a suitable mailing list, a programming chat-room,
or use a QA website like stackoverflow because I'm usually too busy to answer any mails related
to my code snippets. Therefore please just mail me if you found a serious bug... Thank you!


Older comments:

None.