php metaphone() function calculates the metaphone key of a string, this article introduces the php metaphone() function to coders For basic usage and examples, coders in need can refer to the methods and examples in this article.
Definition and usage
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.
Grammar
metaphone(string,length)参数 | 描述 |
---|---|
string | 必需。规定要检查的字符串。 |
length | 可选。规定 metaphone 键的最大长度。 |
Technical details
返回值: | 如果成功则返回字符串的 metaphone 键,如果失败则返回 FALSE。 |
PHP 版本: | 4 |
Example
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); ?>
Example 2
Use length parameter:
<?php $str = "Assistance"; $str2 = "Assistants"; echo metaphone($str,5); echo "<br>"; echo metaphone($str2,5); ?>
The above definition and usage of the php metaphone() function is all the content shared by the editor. I hope it can give you a reference, and I also hope that everyone will support Bangkejia.