Search w3schools.com:

SHARE THIS PAGE

PHP metaphone() Function

PHP String Reference Complete PHP String Reference

Example

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.

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 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 1

Using the metaphone() function on two similar sounding words:

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

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

Run example »

Example 2

Using the length parameter:

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

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

Run example »


PHP String Reference Complete PHP String Reference

W3Schools Certification

W3Schools' Online Certification

The perfect solution for professionals who need to balance work, family, and career building.

More than 10 000 certificates already issued!

Get Your Certificate »

The HTML Certificate documents your knowledge of HTML.

The HTML5 Certificate documents your knowledge of advanced HTML5.

The CSS Certificate documents your knowledge of advanced CSS.

The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.

The jQuery Certificate documents your knowledge of jQuery.

The XML Certificate documents your knowledge of XML, XML DOM and XSLT.

The ASP Certificate documents your knowledge of ASP, SQL, and ADO.

The PHP Certificate documents your knowledge of PHP and SQL (MySQL).

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]