PHP soundex() Function
The PHP soundex() function calculates the soundex key of a string.
Soundex key is a four character long alphanumeric string. It has the property that the words pronounced similarly produce the same soundex key, and can thus be used to simplify searches in databases where the pronunciation is known but not the spelling.
Note: Similar to this function, metaphone() function also creates key based on similar sounding words. metaphone() function is more accurate than soundex() function as it knows the basic rules of English pronunciation.
Syntax
soundex(string)
Parameters
string |
Required. Specify the input string. |
Return Value
Returns the soundex key as a string with four characters. If at least one letter is contained in string, the returned string starts with a letter. Otherwise "0000" is returned.
Example:
The example below shows the usage of soundex() function.
<?php echo "soundex('hair') = ".soundex('hair')."\n"; echo "soundex('heir') = ".soundex('heir')."\n"; echo "soundex('too') = ".soundex('too')."\n"; echo "soundex('to') = ".soundex('to')."\n"; echo "soundex('two') = ".soundex('two')."\n"; ?>
The output of the above code will be:
soundex('hair') = H600 soundex('heir') = H600 soundex('too') = T000 soundex('to') = T000 soundex('two') = T000
❮ PHP String Reference