Download the PHP package iliaal/phonetic without Composer

On this page you can find all versions of the php package iliaal/phonetic. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package phonetic

phonetic

Native phonetic name matching for PHP: Double Metaphone, Beider-Morse Phonetic Matching (BMPM), Daitch-Mokotoff Soundex, NYSIIS, and Match Rating Approach. PHP core ships only soundex() and metaphone(); these are the encoders used for fuzzy name matching, record linkage, and genealogy search across spelling and transliteration variants. Comparison helpers answer "do these two names sound alike?" directly.

Quick start

Install via PIE (requires PHP 8.1 or later):

Then check whether two names sound alike:

Choosing an algorithm

Double Metaphone BMPM Daitch-Mokotoff Soundex NYSIIS Match Rating
Output primary + alternate key language-aware token set distinct 6-digit codes single key compact codex
Two names match when keys are equal token sets intersect code sets intersect keys are equal clear the MRA similarity threshold
Strongest for English and general Latin-script names cross-language and transliteration variants (Slavic, Germanic, Hebrew, Romance) Eastern-European and Ashkenazi surnames, genealogy American/English surnames English names; ships its own similarity test
Spelling-variant recall good highest high, within its language model good good
Ambiguity handling up to 2 keys many tokens multiple codes single key single codex
Relative speed fast (1.0x) slowest (~60x) middle (~2.3x) fast (0.42x) fastest (0.24x)
Data source clean-room published algorithm Apache Commons Codec rule data Apache Commons Codec rule data clean-room published algorithm clean-room published algorithm

Use Double Metaphone as a fast general-purpose default, BMPM when names cross languages or scripts, and Daitch-Mokotoff for Eastern-European and Jewish genealogy, where it is the field standard. NYSIIS and Match Rating Approach are lighter single-key English/American encoders, useful as alternate index keys or as a second check alongside Double Metaphone.

API

Double Metaphone

Primary + alternate phonetic keys (Lawrence Philips). Clean-room implementation.

alternate equals primary when the algorithm produced no alternate branch. max_length caps each key (default 4; 0 or negative = unlimited).

Beider-Morse Phonetic Matching

Language-aware token set. | separates alternatives. With the default concatenation mode, ordinary words form one encoded sequence ("John Smith" becomes "ionzmit"). Recognized generic prefixes use (remainder)-(combined) groups. Matches Apache Commons Codec's default BeiderMorseEncoder.

Empty $language auto-detects. To force a language, pass its exact lowercase token for that name type (e.g. "russian", "english"). Tokens are name-type-specific (GENERIC has the largest set; ASHKENAZI/SEPHARDIC are subsets). You can't force the label "any"; see Notes.

Constants (numeric values):

Constant Value Role
BMPM_GENERIC 0 name type
BMPM_ASHKENAZI 1 name type
BMPM_SEPHARDIC 2 name type
BMPM_APPROX 10 accuracy
BMPM_EXACT 20 accuracy

Accuracy values don't overlap name-type values, so a misplaced constant such as bmpm($s, BMPM_APPROX) is rejected instead of selecting a name type. Use the constant names, not integers.

Invalid $name_type, $accuracy, or unknown $language for the name type raise ValueError. Inputs longer than 4096 bytes and resource-budget overruns also raise ValueError (bounds shared with bmpm_match(); see Notes and limitations).

A forced language also applies to the split variants of prefixed names (van Smith, d'Angelo). This differs from Commons Codec, which re-detects the language inside its prefix branch and ignores the forced set there.

Daitch-Mokotoff Soundex

List of distinct 6-digit codes (the algorithm branches on ambiguous letters). Uses Apache Commons Codec's DaitchMokotoffSoundex branching rules, with the resource limits described in Notes and limitations.

For an empty string, this API returns [] instead of Commons Codec's ["000000"]. Non-empty input that matches no rule still returns ["000000"] for encoder parity with the oracle. Inputs over 4096 bytes or encodings that exceed the work budget throw ValueError.

Indexing caveat: "000000" is also the finished code for pure-vowel inputs that did match a rule (e.g. "A"), so two "000000" encodings don't imply a match. dm_soundex_match("A", "1") is false although both encode to ["000000"]. When you build an inverted index from dm_soundex(), skip the "000000" key or use dm_soundex_match() at query time.

NYSIIS

Single phonetic key (New York State Identification and Intelligence System), tuned for American/English surnames. Reimplementation of the published algorithm; matches Apache Commons Codec's Nysiis.

The classic algorithm truncates to 6 characters; max_length = 0 (or negative) returns the full key.

Match Rating Approach

Compact codex (Western Airlines, 1977). Pair it with its own similarity test instead of comparing codexes for equality.

Use match_rating_compare() (below) to decide whether two names match. It applies the algorithm's length and rating rules, which codex equality skips.

Comparison helpers

Each encoder returns a different output shape, so each needs its own comparison. These helpers implement it, so you don't have to write the set-intersection or match-strength logic in PHP.

Empty or unencodable input never matches anything, including another empty or unencodable input:

Usage

For a one-off check, call a comparison helper:

For indexed lookup, encode once and store the key(s) with each record, then query by encoded value instead of re-encoding at search time. Double Metaphone gives one or two keys per name; Daitch-Mokotoff and BMPM give a set, so index every code. BMPM separates alternatives with |; ordinary words are concatenated, while recognized generic prefixes produce (remainder)-(combined) groups:

Performance

Single-name encode, warm, -O2 non-ASan PHP 8.4 on one core, over a representative mix of 18 names (best of 5 trials). Absolute time scales with input length; the relative ordering holds.

encoder per call throughput relative
match_rating() ~0.043 µs ~23M/sec 0.24x
nysiis() ~0.074 µs ~13M/sec 0.42x
double_metaphone() ~0.18 µs ~5.5M/sec 1.0x
dm_soundex() ~0.41 µs ~2.4M/sec ~2.3x slower
bmpm() ~11 µs ~91k/sec ~60x slower

Match Rating and NYSIIS are short single-key passes. Double Metaphone is one linear pass with a primary/alternate split. Daitch-Mokotoff branches on ambiguous letters and dedups the codes, using a first-byte rule index. BMPM runs language detection, a main transliteration pass, and two final rule passes. Each main pass keeps at most 20 phonemes (ordinary words are concatenated before encoding); each final-pass input phoneme can expand into up to 20 alternatives before the results are merged. The final token set can therefore exceed 20 (bmpm("Kowalowa") returns 32), subject to the cumulative resource budgets. If you know the language, pass $language to skip auto-detection; this can cut bmpm() time several-fold, depending on the language's ruleset.

The comparison helpers cost roughly two encodes plus a cheap compare:

helper per call throughput
match_rating_compare() ~0.11 µs ~9M/sec
nysiis_match() ~0.14 µs ~7M/sec
double_metaphone_match() ~0.26 µs ~3.8M/sec
dm_soundex_match() ~0.80 µs ~1.3M/sec
bmpm_match() ~22 µs ~45k/sec

For repeated lookups against a fixed corpus, encode once and index the keys (see Usage) rather than calling a helper per candidate pair.

Notes and limitations

BMPM resource limits per encoded operand:

Resource Limit
Distinct phonemes added to final-pass sets, cumulatively 2048
Text bytes added with those phonemes, cumulatively 4 MiB (4,194,304 bytes)
Phoneme-text bytes copied while expanding rule alternatives, cumulatively 32 MiB (33,554,432 bytes)
Language-guess scan units: code-point count × rule count per guess 4,194,304 units, cumulatively
Serialized output, including \| separators and prefix punctuation 256 × original input byte length

The output budget counts the combined prefix tree once, including each leaf's serialized bytes and five punctuation bytes per prefix pair. These are specific resource counters, not a wall-clock CPU limit or a total-memory limit. Even short BMPM inputs can exceed a budget; for example, the 14-byte input below raises ValueError. Catch budget exceptions when processing untrusted names or batches:

Input-length policy by function (the 4096-byte caps are checked for both operands of a match helper):

Function(s) Max input Over the limit
bmpm, bmpm_match 4096 bytes throws ValueError
dm_soundex, dm_soundex_match 4096 bytes throws ValueError
double_metaphone, double_metaphone_match C INT_MAX - 11 bytes after folding throws ValueError
nysiis, nysiis_match not capped encodes (bounded by memory)
match_rating, match_rating_compare not capped encodes (bounded by memory)

Double Metaphone checks the folded-byte limit for each operand it encodes; max_length separately limits the returned keys. See the folded-input bound and its dmet_codes() validation.

Double Metaphone, NYSIIS, and Match Rating run in linear time. Match Rating uses constant temporary space; Double Metaphone and NYSIIS use linear space. Bound untrusted input at the application layer if you feed them arbitrary-length strings.

🔗 Native PHP extensions

License

BSD 3-Clause (see LICENSE).

The Beider-Morse and Daitch-Mokotoff rule data is vendored from Apache Commons Codec under the Apache License 2.0. The complete terms are in LICENSE-APACHE; the Commons Codec attribution is in NOTICE, and Section 2 of LICENSE maps the rule data to those files. Double Metaphone, NYSIIS, and Match Rating Approach are independent implementations of their published algorithms, with no third-party code or data. Apache Commons Codec is used only as the parity-test oracle.


Follow @iliaa on X • Blog • If this matched the names exact comparison missed, ⭐ star it!


All versions of phonetic with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package iliaal/phonetic contains the following files

Loading the files please wait ...