soundex()

soundex() — Calculate the soundex key of a string.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

Soundex keys have the property that words pronounced similarly produce the same soundex key, and can thus be used to simplify searches in databases where you know the pronunciation but not the spelling.

Signature

soundex(string $string): string

Parameters

ParameterTypeWhat it takes
$stringstringThe 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

A runnable snippet:

echo soundex("Euler"), PHP_EOL, soundex("Ellery"), PHP_EOL; soundex("Euler") == soundex("Ellery"); // E460 soundex("Gauss") == soundex("Ghosh"); // G200 soundex("Hilbert") == soundex("Heilbronn"); // H416 soundex("Knuth") == soundex("Kant"); // K530 soundex("Lloyd") == soundex("Ladd"); // L300 soundex("Lukasiewicz") == soundex("Lissajous"); // L222

Changelog

VersionChange
8.0.0Prior to this version, calling the function with an empty string returned false for no particular reason.

See also

levenshtein(), metaphone(), similar_text()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page soundex() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.