Home » PHP levenshtein() function

PHP levenshtein() function

by Online Tutorials Library

PHP string levenshtein() Function

PHP string levenshtein() function is in-built function. It is used to calculate the distance between two strings. By default, PHP provides some operations (replace, insert and delete)

It returns the Levenshtein distance between the two argument strings or -1, if the string exceeds 255 characters.

Syntax:

Parameter Description Required/Optional
String1 Specify first string to compare. required
String2 Specify second string to compare. required
cost_ins Specify the cost insertion. Optional
cost_rep Specify the cost of replacement. Optional
cost_del Specify the cost of deletion. Optional

Note: The levenshtein() function is not case-sensitive language.

Example 1

Output:

1  

Example 2

Output:

2  

Example 3

Output:

30  

Example 4

Output:

10  

Next TopicPHP String

You may also like