PHP soundex() Function
In this chapter you will learn:
- Definition for PHP soundex() Function
- Syntax for PHP soundex() Function
- Parameter for PHP soundex() Function
- Note for PHP soundex() Function
- Return for PHP soundex() Function
- Example - Calculate the soundex key of "Hello"
- Example - Using the soundex() function on two similar sounding words
Definition
The soundex() function calculates the soundex key of a string.
Syntax
PHP soundex() Function has the following syntax.
soundex(string)
Parameter
Parameter | Is Required | Description |
---|---|---|
string | Required. | 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//from j a va 2s.co m
$str = "phone";
$str2 = "fone";
echo soundex($str);
echo "<br>";
echo soundex($str2);
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP sprintf() Function
- Syntax for PHP sprintf() Function
- Parameter for PHP sprintf() Function
- Additional format for PHP printf() Function
- Padding the Output
- Specifying Number Precision
- Swapping Arguments
- Return for PHP sprintf() Function
- Note for PHP printf() Function
- Example - Replace format with value
- Example - A demonstration of all possible format values
- Example - Use of placeholders
- Example - A demonstration of string specifiers