levenshtein() – PHP String Functions
Syntax :
OR
levenshtein ( string1, string2, char_ins , char_rep , char_del)
Description :
It’s an inbuilt function of PHP. levenshtein() function will calculate Levenshtein distance between two strings.
Parameter :
[table caption=”” width=”100%” colwidth=”15%|15%|15%|55%” colalign=”left|left|left|left”]
Name, Required /Optional, Value Type, Description
string1, Required, String, Main string to check into.
string2, Required, String, Main string to check into.
char_ins, Optional, Integer, The cost of inserting a character Default is 1.
char_rep, Optional, Integer, The cost of replacing a character Default is 1.
char_del, Optional, Integer, The cost of deleting a character Default is 1.
[/table]
Output :
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.
Related articles : stripos(), strpos(), strripos().
levenshtein() – PHP Functions Example 1 :
<?php echo levenshtein("Hello From Tutorialmines.net"," From Tutor"); echo "<br>"; echo levenshtein("Hello From Tutorialmines.net","From Tutorialmines.net",2,5,3); ?>
Output of above code in the browser is as below:
18