PHP | metaphone() Function

The metaphone() function is a built-in function in PHP and is used to calculate the metaphone key of a given string. The Metaphone key is a phonetic algorithm for indexing of words by their pronunciation. It uses the larger set of rules for English pronunciation.

Syntax:

string metaphone ( $str, $key )

Parameters: This function accepts two parameters as mentioned above and described below:



  • $str: It is Required parameter which represents the string to find the Metaphone key.
  • $key: It is a optional parameter which specified for Maximum length of the metaphone key.

Return Value: It returns the metaphone key as a string, and return FALSE in failure.

Examples:

Input: $str = "Contribute Article on GeeksforGeeks"
Output: KNTRBTRTKLNJKSFRJKS

Input: $str = "Contribute Article on GeeksforGeeks"  $key = 5
Output: KNTRB

Below programs illustrate the metaphone() function in PHP:
Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
$str1 = "Contribute Article on GeeksforGeeks";
echo metaphone($str1) . "\n";
  
$str2 = "A computer science portal";
echo metaphone($str2);
?>

chevron_right


Output:

KNTRBTRTKLNJKSFRJKS
AKMPTRSNSPRTL

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
$str1 = "Contribute Article on GeeksforGeeks";
echo metaphone($str1, 6) . "\n";
  
$str2 = "A computer science portal";
echo metaphone($str2, 5);
?>

chevron_right


Output:

KNTRBT
AKMPT

Related Article: PHP | soundex() Function

Reference: http://php.net/manual/en/function.metaphone.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.