PHP metaphone() Function
Definition and Usage
The metaphone() function calculates the metaphone key of a string.
A metaphone key represents how a string sounds if said by an English speaking person.
The metaphone() function can be used for spelling applications.
Note: The metaphone() function creates the same key for similar sounding words.
Note: The generated metaphone keys vary in length.
Tip: metaphone() is more accurate than the soundex() function, because metaphone() knows the basic rules of English pronunciation.
Syntax
metaphone(string,length)
Parameter Values
Parameter | Description |
---|---|
string | Required. Specifies the string to check |
length | Optional. Specifies the maximum length of the metaphone key |
Technical Details
Return Value: | Returns the metaphone key of the string on success, or FALSE on failure. |
---|---|
PHP Version: | 4+ |
More Examples
Example
Using the metaphone() function on two similar sounding words:
<?php
$str = "Assistance";
$str2 = "Assistants";
echo metaphone($str);
echo "<br>";
echo metaphone($str2);
?>
Try it Yourself »
Example
Using the length parameter:
<?php
$str = "Assistance";
$str2 = "Assistants";
echo metaphone($str,5);
echo "<br>";
echo metaphone($str2,5);
?>
Try it Yourself »
❮ PHP String Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.