Write a function mySoundex($name) that computes the Soundex code for the given p
ID: 673084 • Letter: W
Question
Write a function mySoundex($name) that computes the Soundex code for the given parameter name. Soundex is a set of rules that transforms an English name into a hashcode that can be used for similar names (so looking up a name in a database based on the soundex code will yield similar sounding names). The Soundex rules are given at http://en.wikipedia.org/wiki/Soundex. Note: PHP has a built-in soundex() function that you should NOT use for this assignment (the idea is to write it yourself). Test your function using the names "Euler", "Ellery", "Gauss", "Ghosh", "Hilbert", "Heilbronn", "Knuth", "Kant", "Leida", "Ladd", "Lukasiewicz", and "Lissajous"
Explanation / Answer
soundex is a phonetic algorithm for indexing names by sound, as pronounced in English.The goal is for the names with the same pronunciation to be encoded to the same representation so that they can matched despite minor difference in their speling. the algorithm mainly encodes consonants : avowel will not be encoded unlesss it is a first letter.the soundex code for a name consists of a letter followed by three numerical digits:The letter is the first letter of the name and digits encode the remaining consonants.consonants at similar place of articulation share same digits.let me give the algorithm for soundex;
$code = soundex($name); //#get the soundex code for the name
@codes = soundex(@names);
$code = soundex_nara($name);
@codes = soundex_nara(@names);
$text : : soundex : : nocode = 'Z000';
example
Euler, Ellery -> E460
Gauss,Ghosh -> G200
Hilbert, Heilbronn->H416
Knuth, Kanth -> K530
Lloyd, Ladd -> L300
Lukasiewicz,Lissajous->L222
there soundex are given in their right side as well.
$code = soundex 'Knuth' ; #code contains 'K530'
@list = soundex qw(Lloyd ,Gauss); #@list contains 'L300', 'G200'
$code = soundex 'Hilbert' ; #code contains 'H416'
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.