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 */

Url: http://www.jonasjohn.de/snippets/php/soundex.htm

Language: PHP | User: ShareMySnippets | Created: Oct 16, 2013