The Wayback Machine - https://web.archive.org/web/20231211184801/https://www.geeksforgeeks.org/php-metaphone-function/
Open In App
Related Articles

PHP metaphone() Function

Improve Article
Improve
Save Article
Save
Like Article
Like

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 an 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: 

php




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


Output:

KNTRBTRTKLNJKSFRJKS
AKMPTRSNSPRTL

Program 2: 

php




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


Output:

KNTRBT
AKMPT

Related Article: PHP | soundex() Function 

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

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 21 Jun, 2023
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials