metaphone() function in PHP


The metaphone() function is used to calculate the metaphone key of a string. This is a key that represent how a string sounds if spoken by someone who speaks in English.

Syntax

metaphone(str, len)

Parameters

  • str − The string to check.

  • len − The maximum length of the metaphone key.

Return

The metaphone() function returns the metaphone key of the string on success, or FALSE on failure.

Example

The following is an example −

 Live Demo

<?php
   var_dump(metaphone('demo'));
?>

Output

The following is the output −

string(2) "TM"

Example

Let us see another example −

 Live Demo

<?php
   var_dump(metaphone('Welcome', 3));
?>

Output

The following is the output −

string(3) "WLK"

Example

Let us now see another example of the words that look similar −

 Live Demo

<?php
   $one = "Since";
   $two = "Sins";
   echo metaphone($one);
   echo "<b>";
   echo metaphone($two);
?>

Output

The following is the output −

SNS
SNS

Updated on: 26-Dec-2019

45 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements