Example
Calculate the metaphone key of "World":
<?php echo metaphone("World"); ?>
Definition and usage
metaphone() function calculates the metaphone key of a string.
The metaphone key represents the English pronunciation of the string.
Themetaphone() function can be used in spell checkers.
Note: The metaphone() function creates the same key for words with similar pronunciation.
Note: The generated metaphone keys are of variable length.
Tip: metaphone() is more precise than the soundex() function because metaphone() understands the basic rules of English pronunciation.
Syntax
metaphone(string,length)
Parameter Description
string Required. Specifies the string to check.
length Optional. Specifies the maximum length of metaphone keys.
Technical details
Return value: Returns the metaphone key of the string if successful, returns FALSE if failed.
PHP version: 4+
More examples
Example 1
Use metaphone() function for two words with similar pronunciation:
<?php $str = "Assistance"; $str2 = "Assistants"; echo metaphone($str); echo "<br>"; echo metaphone($str2); ?>
Example 2
Use length parameter:
<?php $str = "Assistance"; $str2 = "Assistants"; echo metaphone($str,5); echo "<br>"; echo metaphone($str2,5); ?>
The above is the detailed content of PHP calculates the key function metaphone() of a string. For more information, please follow other related articles on the PHP Chinese website!