PHP metaphone()Functions

PHP String 参考手册PHP String Reference Manual

Examples

Calculate the metaphone key of "World":

<?php
echo metaphone("World");
?>

Run example »

Definition and Usage

The metaphone() function calculates the metaphone key of a string.

The metaphone key represents the English pronunciation of a string.

The metaphone() function can be used in spell-checking programs.

Note:The metaphone() function creates the same key for similarly pronounced words.

Note:The generated metaphone key has a variable length.

Tip:metaphone() issoundex()more accurate than the function, because metaphone() understands the basic rules of English pronunciation.


Syntax

metaphone(string,length)

Parameters Description
string Required. Specifies the string to be checked.
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 1

Use the metaphone() function on two words with similar pronunciation:

<?php
$str = "Assistance";
$str2 = "Assistants";

echo metaphone($str);
echo "<br>";
echo metaphone($str2);
?>

Run example »

Example 2

Use the length parameter:

<?php
$str = "Assistance";
$str2 = "Assistants";

echo metaphone($str,5);
echo "<br>";
echo metaphone($str2,5);
?>

Run example »


PHP String 参考手册PHP String Reference Manual Other Extensions