Php soundex
From w3cyberlearnings
Contents |
PHP function soundex
This function returns the soundex key of a string. The soundex key is the four characters length of a word that represent the English pronunciation of a word.
Syntax soundex
- word: string of a word
soundex(word);
Example 1
<?php $sk1 = 'Woman'; $sk2 = 'Women'; echo soundex($sk1). '<br/>'; echo soundex($sk2). '<br/>'; ?>
Output
W550 W550
Example 2
<?php $sk1 = 'Master'; $sk2 = 'Matter'; echo soundex($sk1). '<br/>'; echo soundex($sk2). '<br/>'; ?>
Output
M236 M360
Example 3
- Reverse the word order and find their soundex code.
<?php $sk1 = 'Master'; $sk2 = 'Matter'; echo soundex(strrev($sk1)). '<br/>'; echo soundex(strrev($sk2)). '<br/>'; ?>
Output
R325 R350
Example 4
<?php $search_key1 = 'dog'; $array_list = array('man', 'woman', 'goose', 'ghost', 'girl', 'golf', 'dog', 'dot', 'dogg', 'dott'); for ($i = 0; $i < count($array_list); $i++) { $key1_soundex = soundex($search_key1); if($key1_soundex == soundex($array_list[$i])) { echo $array_list[$i]. ' soundex code: '. $key1_soundex .'<br/>'; } } ?>
Output
dog soundex code: D200 dogg soundex code: D200