(PHP 4, PHP 5, PHP 7)

metaphone문자열의 메타폰 키를 계산


string metaphone ( string $str [, int $phones ] )

str의 메타폰 키를 계산합니다.

soundex()처럼 메타폰은 유사한 발음의 단어에 대해 동일한 키를 생성합니다. 이 함수는 영어 발음의 기본 법칙을 사용하는soundex()보다 훨씬 정확합니다. 메타폰 생성 키는 가변 길이를 가집니다.

메타폰은 Lawrence Philips <lphilips at verity dot com>가 개발하였습니다. 이는 ["Practical Algorithms for Programmers", Binstock & Rex, Addison Wesley, 1995]에 수록되어 있습니다.



입력 문자열.



메타폰 키를 문자열로 반환합니다.

add a note add a note

User Contributed Notes 6 notes

mail at spam-off dot iaindooley dot com
18 years ago
you can use the metaphone function quite effectively with phrases by taking the levenshtein distances between two metaphone codes, and then taking this as a percentage of the length of the original metaphone code. thus you can define a percentage error, (say 20%) and accept only matches that are closer than that. i've found this works quite effectively in a function i am using on my website where an album name that the user entered is verified against existing album names that may be similar. this is also an excellent way of people being able to vaguely remember a phrase and get several suggestions out of the database. so you could type "i stiched nine times" with an error percentage of, say, 50 and still get 'a stitch in time saves nine' back as a match.
php at casadebender dot com
14 years ago
A double metaphone pecl module is available:
Vipindas K.S
14 years ago
The metaphone() function can be used for spelling applications.This function returns the metaphone key of the string on success, or FALSE on failure.Its main use is when you are searching a genealogy database. check to see if a metaphone search is offered. It is also useful in making/searching family tree.
Given below is a simple code that calculates and compares two strings to find whether its metaphone codes are equivalent.

html code
<form action="test.php" name="test" method="get">
Name1:<input type="text" name="name1" /><br />
Name2:<input type="text" name="name2" /><br />
<input type="submit" name="submit" value="compare" />

<!--php code begins here -->

$str1 = $_GET['name1'];
$str2 = $_GET['name2'];
"metaphone code for ".$str1." is ". $meta_one;
"<br />";
"metaphone code for ".$str2." is ". $meta_two."<br>";
"metaphone codes are matching";
"metaphone codes are not matching";


Metaphone  algorithm was developed by Lawrence Philips.

Lawrence Philips' RULES follow:

The 16 consonant sounds:
                                             |--- ZERO represents "th"
      B  X  S  K  J  T  F  H  L  M  N  P  R  0  W  Y


   Beginning of word: "ae-", "gn", "kn-", "pn-", "wr-"  ----> drop first letter
                      "Aebersold", "Gnagy", "Knuth", "Pniewski", "Wright"

   Beginning of word: "x"                                ----> change to "s"
                                      as in "Deng Xiaopeng"

   Beginning of word: "wh-"                              ----> change to "w"
                                      as in "Whalen"


   B ----> B      unless at the end of word after "m", as in "dumb", "McComb"

   C ----> X      (sh) if "-cia-" or "-ch-"
           S      if "-ci-", "-ce-", or "-cy-"
                  SILENT if "-sci-", "-sce-", or "-scy-"
           K      otherwise, including in "-sch-"

   D ----> J      if in "-dge-", "-dgy-", or "-dgi-"
           T      otherwise

   F ----> F

   G ---->        SILENT if in "-gh-" and not at end or before a vowel
                            in "-gn" or "-gned"
                            in "-dge-" etc., as in above rule
           J      if before "i", or "e", or "y" if not double "gg"
           K      otherwise

   H ---->        SILENT if after vowel and no vowel follows
                         or after "-ch-", "-sh-", "-ph-", "-th-", "-gh-"
           H      otherwise

   J ----> J

   K ---->        SILENT if after "c"
           K      otherwise

   L ----> L

   M ----> M

   N ----> N

   P ----> F      if before "h"
           P      otherwise

   Q ----> K

   R ----> R

   S ----> X      (sh) if before "h" or in "-sio-" or "-sia-"
           S      otherwise

   T ----> X      (sh) if "-tia-" or "-tio-"
           0      (th) if before "h"
                  silent if in "-tch-"
           T      otherwise

   V ----> F

   W ---->        SILENT if not followed by a vowel
           W      if followed by a vowel

   X ----> KS

   Y ---->        SILENT if not followed by a vowel
           Y      if followed by a vowel

   Z ----> S
Ray.Paseur often uses Gmail
9 years ago
Metaphone() apparently ignores non-English characters.  Comparing Plaçe TO Place yields "PL" and "PLS."  A similar result comes from soundex().
isloera at usedformyjunk dot com
8 years ago
I changed my domain so the code for spanish_methaphone  is here

Please update the link ;-)
isloera at usedformyjunk dot com
8 years ago
I changed my domain so the code for spanish_methaphone  is here

Please update the link ;-)
To Top