Php metaphone
From w3cyberlearnings
Contents |
PHP function metaphone
This function calculates the metaphone key of a given string. This metaphone() function is similar to php soundex
Syntax metaphone
- string: string to be calcualted.
- length: maximum length of the metaphone key.
metaphone(string, length);
Example 1
<?php $str='dot'; echo metaphone($str); ?>
Output
TT
Example 2
<?php $array_str = array('dot', 'dott', 'dog', 'dogg', 'dorm', 'doll', 'sweet', 'sweat', 'tea', 'ty', 'li', 'lee' ); for ($i = 0; $i < count($array_str); $i++) { echo $array_str[$i] . '-->' . metaphone($array_str[$i]) . '<br/>'; } ?>
Output
dot-->TT dott-->TT dog-->TK dogg-->TK dorm-->TRM doll-->TL sweet-->SWT sweat-->SWT tea-->T ty-->T li-->L lee-->L