PHP.mk документација

metaphone

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.metaphone.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.metaphone.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
metaphone

Референца за `function.metaphone.php` со подобрена типографија и навигација.

function.metaphone.php

metaphone

(PHP 4, PHP 5, PHP 7, PHP 8)

metaphoneПресметај го метафонскиот клуч на стринг

= NULL

metaphone(string $string, int $max_phonemes = 0): string

Пресметува метафонски клуч на string.

Слично на soundex() метафон создава ист клуч за зборови што звучат слично. Поточен е од soundex() бидејќи ги знае основните правила на англискиот изговор. Метафонски генерираните клучеви се со променлива должина.

Метафон е развиен од Лоренс Филипс <lphilips at verity dot com>. Опишан е во ["Practical Algorithms for Programmers", Binstock & Rex, Addison Wesley, 1995].

Параметри

string

, и враќа стринг со првиот карактер од

max_phonemes

Овој параметар го ограничува вратениот метафонски клуч на max_phonemes characters во должина. Сепак, добиените фонеми секогаш се транскрибираат целосно, така што должината на добиениот стринг може да биде малку подолга од max_phonemes. Стандардната вредност на 0 значи без ограничување.

Вратени вредности

Враќа метафонски клуч како стринг.

Дневник на промени

Верзија = NULL
8.0.0 Функцијата врати false при неуспех.

Примери

Пример #1 metaphone() основен пример

<?php
var_dump
(metaphone('programming'));
var_dump(metaphone('programmer'));
?>

Пример #1 Пример што покажува затворачка ознака што го опфаќа последниот нов ред

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

Пример #2 Користејќи го max_phonemes parameter

<?php
var_dump
(metaphone('programming', 5));
var_dump(metaphone('programmer', 5));
?>

Пример #1 Пример што покажува затворачка ознака што го опфаќа последниот нов ред

string(5) "PRKRM"
string(5) "PRKRM"

Пример #3 Користејќи го max_phonemes parameter

Во овој пример, metaphone() се препорачува да се произведе стринг од пет знаци, но тоа би барало да се подели последната фонема ('x' треба да се транскрибира во 'KS'), така што функцијата враќа стринг со шест знаци.

<?php
var_dump
(metaphone('Asterix', 5));
?>

Пример #1 Пример што покажува затворачка ознака што го опфаќа последниот нов ред

string(6) "ASTRKS"

Види Исто така

  • levenshtein() - Пресметај ја Левитенштајновата далечина помеѓу два низи
  • similar_text() - Пресметај ја сличноста помеѓу две низи
  • soundex() - Пресметај го саундексот на низа

Белешки од корисници 4 белешки

mail на spam-off dot iaindooley dot com
пред 22 години
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.
Vipindas K.S
пред 17 години
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
php на casadebender dot com
пред 17 години
A double metaphone pecl module is available: http://pecl.php.net/package/doublemetaphone
Ray.Paseur често користи Gmail
12 години пред
Metaphone() apparently ignores non-English characters.  Comparing Plaçe TO Place yields "PL" and "PLS."  A similar result comes from soundex().
Навигација

Прелистувај сродни теми и функции.

На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.