The metaphone() function calculates the metaphone key of a string.
A metaphone key represents how a string sounds in English. The metaphone() function creates the same key for similar sounding words.
metaphone() is more accurate than the soundex() function.
PHP metaphone() Function has the following syntax.
metaphone(string,length)
Parameter | Is Required | Description |
---|---|---|
string | Required. | String to check |
length | Optional. | Maximum length of the metaphone key |
PHP metaphone() Function returns the metaphone key of the string on success, or FALSE on failure.
Calculate the metaphone key of "World":
<?php
echo metaphone("java2s.com");
?>
The code above generates the following result.
Using the metaphone() function on two similar sounding words:
<?php
$str = "phone";
$str2 = "fone";
echo metaphone($str);
echo "\n";
echo metaphone($str2);
?>
The code above generates the following result.
Using the length parameter of the metaphone() function on two similar sounding words:
<?php
$str = "phone";
$str2 = "fone";
echo metaphone($str,5);
echo "\n";
echo metaphone($str2,5);
?>
The code above generates the following result.