String Functions

PHP soundex() Function

Topic: PHP String ReferencePrev|Next


The soundex() function calculates the soundex key of a string.

Soundex key is a short alphanumeric string that represent English pronunciation of a word.

The following table summarizes the technical details of this function.

Return Value: Returns the soundex key as a string, or FALSE on failure.
Version: PHP 4+


The basic syntax of the soundex() function is given with:


The following example shows the soundex() function in action.

// Sample string
$str = "Hello";

// Calculating soundex key
echo soundex($str); // Outputs: H400

Note: The soundex() function returns a 4 characters long string, starting with a letter. Words that pronounced similarly produce the same soundex key, so it can be used to simplify the searches in databases where you know the pronunciation but not the spelling.

Tip: The metaphone() function, which also creates the same key for similar sounding words, is more accurate than soundex(), because it knows the basic rules of English pronunciation.


The soundex() function accepts the following parameters.

Parameter Description
string Required. Specifies the input string.

More Examples

Here're some more examples showing how soundex() function actually works:

The following example demonstrates the use of this function on similar sounding words:

// Sample strings
$str1 = "Desert";
$str2 = "Dessert";

// Calculating soundex key
echo soundex($str1); // Outputs: D263
echo soundex($str2); // Outputs: D263
Bootstrap UI Design Templates