PHP Tutorial - PHP soundex() Function






Definition

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

Syntax

PHP soundex() Function has the following syntax.

soundex(string)

Parameter

ParameterIs RequiredDescription
stringRequired. String to check

Note

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.





Return

PHP soundex() Function returns the soundex key of the string on success, or FALSE on failure.

Example

Calculate the soundex key of "Hello":


<?php
$str = "Hello";
echo soundex($str);
?>

The code above generates the following result.

Example 2

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.