百科狗-知识改变命运!
--

metaphone() - 计算字符串的变音键 - php 字符串函数

梵高1年前 (2023-11-21)阅读数 18#技术干货
文章标签类似于

metaphone()

(PHP 4, PHP 5, PHP 7)

计算字符串的变音键

说明

metaphone(string $str[,int $phonemes= 0]): string

计算字符串的变音键$str.

Similar tosoundex()metaphone creates the same key for similar sounding words. It's more accurate thansoundex()as it knows the basic rules of English pronunciation. The metaphone generated keys are of variable length.

Metaphone was developed by Lawrence Philips . It is described in["Practical Algorithms for Programmers", Binstock & Rex, Addison Wesley, 1995].

参数

$str

The input string.

$phonemes

This parameter restricts the returned metaphone key to$phonemescharacters in length. The default value of0means no restriction.

返回值

metaphone() - 计算字符串的变音键 - php 字符串函数

Returns the metaphone key as a string,或者在失败时返回FALSE.

范例

Example #1metaphone()basic example

以上例程的输出类似于:

string(7) "PRKRMNK"
string(6) "PRKRMR"

Using the$phonemesparameter

以上例程的输出类似于:

string(5) "PRKRM"
string(5) "PRKRM"
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.
A double metaphone pecl module is available: http://pecl.php.net/package/doublemetaphone
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
==========



Name1:
Name2:
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
Metaphone() apparently ignores non-English characters. Comparing Plaçe TO Place yields "PL" and "PLS." A similar result comes from soundex().
I changed my domain so the code for spanish_methaphone is here
http://www.ojocaliente.net/spanish_metaphone.php
Please update the link ;-)
I changed my domain so the code for spanish_methaphone is here
http://www.ojocaliente.net/spanish_metaphone.php
Please update the link ;-)

鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com

免责声明:我们致力于保护作者版权,注重分享,当前被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!邮箱:344225443@qq.com)

图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!

内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)