Home > PHP > Function > Strings > levenshtein()

levenshtein()

levenshtein - Calculate Levenshtein distance between two strings

Syntax

int levenshtein (string $str1, string $str2, string $str1, string $str2, int $cost_ins, int $cost_rep, int $cost_del, string $str1, string $str2, string $str1, string $str2, int $cost_ins, int $cost_rep, int $cost_del)

Arguments

  • str1 - One of the strings being evaluated for Levenshtein distance.
  • str2 - One of the strings being evaluated for Levenshtein distance.
  • str1 - Defines the cost of insertion.
  • str2 - Defines the cost of replacement.
  • cost_ins - Defines the cost of deletion.
  • cost_rep
  • cost_del
  • str1 - One of the strings being evaluated for Levenshtein distance.
  • str2 - One of the strings being evaluated for Levenshtein distance.
  • str1 - Defines the cost of insertion.
  • str2 - Defines the cost of replacement.
  • cost_ins - Defines the cost of deletion.
  • cost_rep
  • cost_del

Description

The Levenshtein distance is defined as the minimal number of characters you have to replace, insert or delete to transform str1 into str2. The complexity of the algorithm is O(m*n), where nand mare the length of str1 and str2 (rather good when compared to similar_text(), which is O(max(n,m)**3), but still expensive).

Version

PHP 4.0.1, 5

Return value

This function returns the Levenshtein-Distance between the two argument strings or -1, if one of the argument strings is longer than the limit of 255 characters.