string levenshtein function - it calculates how may characters to be changed to make two strings identical
string-levenshtein-function-in-php.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>string levenshtein function - it calculates how may characters to be changed to make two strings identical</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Md Iqbal Hosan">
<meta name="title" content="string levenshtein function - it calculates how may characters to be changed to make two strings similar">
<meta name="keywords" content="php, example, code, array, function, levenshtein , string">
<meta name="description" content="string levenshtein function - it calculates how may characters to be changed to make two strings similar">
<style>
h2, h4{background:#eee; color:#000084;}
h2{ padding:3px; margin:3px; font-size:22px;}
h4{ padding:2px; margin:2px; font-size:19px;}
p{padding:2px; margin:2px; color:#0099aa;}
body{ background:#FFFFFc;}
</style>
</head>
<body>
<h2>string levenshtein function - it calculates how may characters to be changed to make two strings similar</h2>
<pre>
<?php
/*
-------------------------------------------
let me tell you my boss's favourite color.
-------------------------------------------
*/
$myBossFavouriteColor = "my boss's favourite color is orange.";
echo "<h4>Output of myBossFavouriteColor</h4>";
print "<p>$"."myBossFavouriteColor = {$myBossFavouriteColor}</p>";
/*
-------------------------------------------
and
-------------------------------------------
*/
$myBossName = "my boss's name is Sk Saiful Islam (cfsuman).";
echo "<h4>Output of myBossName</h4>";
print "<p>$"."myBossName = {$myBossName}</p>";
/*
---------------------------------------------------------------------------
now i want to calculate how many characters i have to change to make
both string identical and i can do it by using string levenshtein function
---------------------------------------------------------------------------
*/
$charactersHaveToChange = levenshtein($myBossFavouriteColor, $myBossName);
echo "<h4>Output of charactersHaveToChange by using string levenshtein function</h4>";
print "<p>$"."charactersHaveToChange = {$charactersHaveToChange}</p>";
/*
---------------------------------------------------------------------------
let's test another example to make a clear concept of levenshtein function
---------------------------------------------------------------------------
*/
$charactersHaveToChange2 = levenshtein('modon','modon');
echo "<h4>Output of charactersHaveToChange2 by using string levenshtein function</h4>";
print "<p>$"."charactersHaveToChange2 = {$charactersHaveToChange2}</p>";
?>
</pre>
</body>
</html>

No comments:
Post a Comment
leave your comments here..