Soundex Function
soundex function calculates a sound key for a given string.
The soundex key consists of the first letter of the string, followed by three digits
that represent the main sound characteristics of the rest of the string.
This algorithm is especially useful for finding names that sound similar
but may be spelled differently.
Syntax
soundex(string);
Example
Get the soundex key for the string "Hello":
<?php
echo soundex('Hello');
?>
Code execution result:
'H400'
Example
Compare soundex keys for words that sound similar:
<?php
$res1 = soundex('Robert');
$res2 = soundex('Rupert');
echo $res1 . ' ' . $res2;
?>
Code execution result:
'R163 R163'
Example
Check soundex keys for different words:
<?php
$words = ['Hello', 'Hallo', 'Hullo', 'World'];
foreach ($words as $word) {
echo $word . ': ' . soundex($word) . "\n";
}
?>
Code execution result:
Hello: H400
Hallo: H400
Hullo: H400
World: W643
See Also
-
levenshteinfunction,
which calculates the distance between strings -
metaphonefunction,
which returns the metaphone key for a string