PHP metaphone() Function
In this chapter you will learn:
- Definition for PHP metaphone() Function
- Syntax for PHP metaphone() Function
- Parameter for PHP metaphone() Function
- Return for PHP metaphone() Function
- Example - PHP metaphone() Function
- Example - Using the metaphone() function on two similar sounding words
- Example - Using the length parameter of the metaphone() function on two similar sounding words
Definition
The metaphone() function calculates the metaphone key of a string.
A metaphone key represents how a string sounds in English. The metaphone() function creates the same key for similar sounding words.
metaphone() is more accurate than the soundex() function.
Syntax
PHP metaphone() Function has the following syntax.
metaphone(string,length)
Parameter
Parameter | Is Required | Description |
---|---|---|
string | Required. | String to check |
length | Optional. | Maximum length of the metaphone key |
Return
PHP metaphone() Function returns the metaphone key of the string on success, or FALSE on failure.
Example 1
Calculate the metaphone key of "World":
<?php
echo metaphone("java2s.com");
?>
The code above generates the following result.
Example 2
Using the metaphone() function on two similar sounding words:
<?php/*from jav a2 s . co m*/
$str = "phone";
$str2 = "fone";
echo metaphone($str);
echo "\n";
echo metaphone($str2);
?>
The code above generates the following result.
Example 3
Using the length parameter of the metaphone() function on two similar sounding words:
<?php/*from j a v a 2s. co m*/
$str = "phone";
$str2 = "fone";
echo metaphone($str,5);
echo "\n";
echo metaphone($str2,5);
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP money_format() Function
- Syntax for PHP money_format() Function
- Parameter for PHP money_format() Function
- Return for PHP money_format() Function
- Note for PHP money_format() Function
- Example - International en_US format
- Example - Italian national format with 2 decimals
- Example - US national format, using () for negative numbers
- Example - Adding the use of 2 digits of right precision and '*' as a fill character
- Example - justify to the left
- Example - add some words before and after the conversion specification