The soundex() function calculates the soundex key of a string.
PHP soundex() Function has the following syntax.
soundex(string)
Parameter | Is Required | Description |
---|---|---|
string | Required. | String to check |
A soundex key is a four character long alphanumeric string that represent English pronunciation of a word.
The soundex() function creates the same key for similar sounding words.
metaphone() is more accurate than soundex(), because metaphone() knows the basic rules of English pronunciation.
PHP soundex() Function returns the soundex key of the string on success, or FALSE on failure.
Calculate the soundex key of "Hello":
<?php
$str = "Hello";
echo soundex($str);
?>
The code above generates the following result.
Using the soundex() function on two similar sounding words:
<?php
$str = "phone";
$str2 = "fone";
echo soundex($str);
echo "<br>";
echo soundex($str2);
?>
The code above generates the following result.