note 83095 added to function.metaphone
| From: | VipindasK dot S at osu1 dot php dot net | Date: | Fri, 09 May 2008 16:49:23 +0000 |
| Subject: | note 83095 added to function.metaphone | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-139221@lists.php.net to get a copy of this message | ||
metaphone
=======================
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
==========
<html>
<body>
<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" />
</form>
<!--php code begins here -->
<?php
if(isset($_GET['submit']))
{
$str1 = $_GET['name1'];
$str2 = $_GET['name2'];
$meta_one=metaphone($str1);
$meta_two=metaphone($str2);
echo "metaphone code for ".$str1." is ". $meta_one;
echo "<br />";
echo "metaphone code for ".$str2." is ". $meta_two."<br>";
if($meta_one==$meta_two)
{
echo "metaphone codes are matching";
}
else
{
echo "metaphone codes are not matching";
}
}
?>
</body>
</html>
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
Exceptions:
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"
Transformations:
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
----
Server IP: 59.162.86.33
Probable Submitter: 59.93.9.84
----
Manual Page -- http://www.php.net/manual/en/function.metaphone.php
Edit -- https://master.php.net/note/edit/83095
Del: integrated -- https://master.php.net/note/delete/83095/integrated
Del: useless -- https://master.php.net/note/delete/83095/useless
Del: bad code -- https://master.php.net/note/delete/83095/bad+code
Del: spam -- https://master.php.net/note/delete/83095/spam
Del: non-english -- https://master.php.net/note/delete/83095/non-english
Del: in docs -- https://master.php.net/note/delete/83095/in+docs
Del: other reasons-- https://master.php.net/note/delete/83095
Reject -- https://master.php.net/note/reject/83095
Search -- https://master.php.net/manage/user-notes.php