Hướng dẫn php soundex vs metaphone - php soundex so với metaphone

[PHP 4, PHP 5, PHP 7, PHP 8]

soundexCalculate the soundex key of a string

Description

soundex[string $string]: string

Soundex keys have the property that words pronounced similarly produce the same soundex key, and can thus be used to simplify searches in databases where you know the pronunciation but not the spelling.

This particular soundex function is one described by Donald Knuth in "The Art Of Computer Programming, vol. 3: Sorting And Searching", Addison-Wesley [1973], pp. 391-392.

Parameters

string

The input string.

Return Values

Returns the soundex key as a string with four characters. If at least one letter is contained in string, the returned string starts with a letter. Otherwise "0000" is returned.

Changelog

VersionDescription
8.0.0 Prior to this version, calling the function with an empty string returned false for no particular reason.

Examples

Example #1 Soundex Examples

See Also

  • levenshtein[] - Calculate Levenshtein distance between two strings
  • metaphone[] - Calculate the metaphone key of a string
  • similar_text[] - Calculate the similarity between two strings

nicolas dot zimmer at einfachmarke dot de

14 years ago

Since soundex[] does not produce optimal results for German language
we have written a function to implement the so called Kölner Phonetik
[Cologne Phonetic].

Please find the code below in the hope it might be useful:

Dirk Hoeschen - Feenders de

8 years ago

I made some improvements to the "Cologne Phonetic" function of niclas zimmer. Key and value of the arrays are inverted to uses simple arrays instead of multidimensional arrays. Therefore all loops and iterations are not longer necessary to find the matching value  for a char.
I put the function into a static class and moved the array declarations outside the function.

The result is more reliable and five times faster than the original.

Bài Viết Liên Quan

Chủ Đề