PHP's levenshtein() counts how many edits it takes to turn one string into another, but it works on bytes, so it gives odd results on multibyte text like accented or non-Latin characters. This RFC from Yuya Hamada proposed adding mb_levenshtein() to the mbstring extension, which counts edits in Unicode code points so each character counts once.

How it works

The new function has the same signature as the old one, plus an encoding parameter:

function mb_levenshtein(
    string $string1,
    string $string2,
    int $insertion_cost = 1,
    int $replacement_cost = 1,
    int $deletion_cost = 1,
    ?string $encoding = null
): int {}

A code point isn't always what you see as a single letter. An "é" can be one code point, or an "e" followed by a combining accent mark, and this function treats those two forms as different:

var_dump(mb_levenshtein("\u{0065}\u{0301}", "\u{00e9}")); // "é" result is 1.

The author said a separate grapheme_levenshtein() function would cover the case where you want those two forms to match.

What it means for existing code

Nothing changes for code you already have. The only risk is a name clash: if your code defines its own mb_levenshtein() function, it would break.

The vote

Declined 1 to 5, short of the two-thirds majority it needed. Voting closed on March 8, 2025. The RFC targeted PHP 8.5.