PHP metaphone() Function


The metaphone() function calculates the metaphone key for a string. A metaphone key describes how a string of letters sounds when spoken by an English speaker. This function can be used in spelling applications and creates identical keys for similarly-sounding words. The length of the metaphone keys generated varies.

Syntax
metaphone(string,length)
Parameters
  • string - (Required) Specify the string to check.
  • length - (Optional) Specifies the maximum length of metaphone keys.
Example
<?php
echo metaphone("Welcome");
?>

Output

WLKM

Using length parameter

Example
<?php
$txt1 = "Welcome";
$txt2 = "Welcome You";
echo metaphone($txt1,2)."<br>";
echo metaphone($txt2,5);
?>

Output

WL
WLKMY

Prev Next