PHP metaphone() Function
PHP metaphone() Function
The metaphone() function in PHP calculates the metaphone key (representing how a string sounds or pronounced) of a string. This function is used to text search and text matching or spelling applications.
Syntax
metaphone ( string $str [, int $phonemes ] )
Parameter
str(required)- This parameter specifies the input string.
phonemes(optional)- This parameter specifies the maximum length of the metaphone key and restricts the returned metaphone key. The default value is 0 (means no restriction).
Return
This function returns the metaphone key as a string or FALSE on failure.
Example 1
Output
Actual String: Hello World Metaphone string: HLWRLT
Example 2
Output
String 1: Principle Metaphone string: PRNSPL String 2: Principal Metaphone string: PRNSPL
Example 3
Output
String 1: Principle Metaphone string: PR String 2: Principal Metaphone string: PRNS
Example 4
Output
YR ER