Home >>PHP String Functions >PHP metaphone() Function
PHP metaphone() function is used to calculate the metaphone key of a given input string. This function is used in text search and text matching applications. The Metaphone key is a phonetic algorithm developed by Lawrence Philips for indexing of words by their pronunciation. The metaphone keys which are generated by the function vary in length. It is more accurate than the soundex() function because it uses the larger set of rules for English pronunciation. This function creates same key for similar sounding words.
Syntax:-
metaphone($string, $key);
Parameter | Description |
---|---|
string | This is a required parameter. This parameter Specifies the given input string. |
key | This is an optional parameter. This parameter specifies the maximum length of the metaphone key. |
Here is an example of metaphone() function in PHP:
<html> <body> <?php echo metaphone("PHPTPOINT"); ?> </body> </html>
Here is an another example of metaphone() function in PHP for two similar sounding words:
<html> <body> <?php $str1 = "coaching"; $str2 = "catching"; echo metaphone($str1); echo "<br>"; echo metaphone($str2); ?> </body> </html>
Here is an another example of metaphone() function in PHP using the $key parameter:
<html> <body> <?php $str = "PHPTPOINT"; echo metaphone($str); echo "<br>"; echo metaphone($str,4); echo "<br>"; echo metaphone($str,2); ?> </body> </html>