php metaphone() function calculates the metaphone key of a string. This article introduces the basic usage of php metaphone() function to coders. Coders who need it can refer to the methods and examples in this article.
The metaphone() function calculates the metaphone key of a string.
The metaphone key represents the English pronunciation of the string.
The metaphone() function can be used in spell checkers.
Note: The metaphone() function creates the same key for words that sound similar.
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.
metaphone(string,length)
参数 | 描述 |
---|---|
string | 必需。规定要检查的字符串。 |
length | 可选。规定 metaphone 键的最大长度。 |
返回值: | 如果成功则返回字符串的 metaphone 键,如果失败则返回 FALSE。 |
PHP 版本: | 4 |
Example 1
Use the metaphone() function for two words that sound similar:
<?php $str = "Assistance"; $str2 = "Assistants"; echo metaphone($str); echo "<br>"; echo metaphone($str2); ?>
Run online
Example 2
Use length parameter:
<?php $str = "Assistance"; $str2 = "Assistants"; echo metaphone($str,5); echo "<br>"; echo metaphone($str2,5); ?>
Run online
Original address: http://www.manongjc.com/article/816.html