PHP Damarau levenstein on Longest Match SubString
Teddy Zugana
Posted on July 29, 2021
function getLongestMatchingSubstring($str1, $str2)
{
$len_1 = strlen($str1);
$longest = '';
for($i = 0; $i < $len_1; $i++){
for($j = $len_1 - $i; $j > 0; $j--){
$sub = substr($str1, $i, $j);
if (strpos($str2, $sub) !== false && strlen($sub) > strlen($longest)){
$longest = $sub;
break;
}
}
}
return $longest;
}
💖 💪 🙅 🚩
Teddy Zugana
Posted on July 29, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
docker Docker Compose Demo: Running Multiple Services with Two Domains on Localhost
November 29, 2024
undefined file_put_contents(...): Failed to open stream: No such file or directory
November 28, 2024