We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

hxseven on 08/14/06


Tagged

php example soundex similar


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

luman


soundex examples


Published in: PHP 


URL: http://codedump.jonasjohn.de/snippets/soundex.htm

  1. $word2find = 'stupid';
  2.  
  3. $words = array(
  4. 'stupid',
  5. 'stu and pid',
  6. 'hello',
  7. 'foobar',
  8. 'stpid',
  9. 'supid',
  10. 'stuuupid',
  11. 'sstuuupiiid',
  12. );
  13.  
  14. while(list($id, $str) = each($words)){
  15.  
  16. $soundex_code = soundex($str);
  17.  
  18. if (soundex($word2find) == $soundex_code){
  19. print '"' . $word2find . '" sounds like ' . $str;
  20. }
  21. else {
  22. print '"' . $word2find . '" sounds not like ' . $str;
  23. }
  24.  
  25. print "\n";
  26. }
  27.  
  28. /*
  29. result:
  30.  
  31. "stupid" sounds like stupid
  32. "stupid" sounds not like stu and pid
  33. "stupid" sounds not like hello
  34. "stupid" sounds not like foobar
  35. "stupid" sounds like stpid
  36. "stupid" sounds not like supid
  37. "stupid" sounds like stuuupid
  38. "stupid" sounds like sstuuupiiid
  39. */

Report this snippet 

You need to login to post a comment.