• PHP Video Tutorials

PHP - Function Levenshtein



Syntax

int levenshtein ( string $str1 , string $str2 )

Definition and Usage

It is used calculate Levenshtein distance between two strings

Return Values

It returns the levenshtein distance between two arguments strings or else it returns -1 on false case

Parameters

Sr.No Parameters & Description
1

str1

One of the strings being evaluated for Levenshtein distance.

2

str2

Second strings being evaluated for Levenshtein distance.

3

cost_ins

Defines the cost of insertion.

4

cost_del

Defines the cost of deletion.

Example

Try out the following example

<?php
   echo 'the distance between two strings is ';
   echo levenshtein("Hello World","ello World");
?>

This will produce following result − −

the distance between two strings is 1
php_function_reference.htm
Advertisements