3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function LevenshteinDistance($str1, $str2) { $d = array (); $len1 = strlen($str1); $len2 = strlen($str2); for ($i1 = 0; $i1 <= $len1; $i1++) { $d[$i1] = array (); $d[$i1][0] = $i1; } for ($i2 = 0; $i2 <= $len2; $i2++) { $d[0][$i2] = $i2; } for ($i1 = 1; $i1 <= $len1; $i1++) { for ($i2 = 1; $i2 <= $len2; $i2++) { $cost = ($str1[$i1 - 1] == $str2[$i2 - 1]) ? 0 : 1; $d[$i1][$i2] = min( $d[$i1 - 1][$i2 ] + 1, //挿入 $d[$i1 ][$i2 - 1] + 1, //削除 $d[$i1 - 1][$i2 - 1] + $cost //置換 ); } } return $d[$len1][$len2]; } echo LevenshteinDistance("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","qwertyuioasdfghjklzxcvbnmfghjkyudfghjkcvbnmqwertyudfghjxcvbnqwertyuioplkjhgfdsamnbcvbhfeghipnvcseaaaaaaaaaaaaaaaaaaaaaaaaafjjuuuuuuuuuuuuuuuuuuuuuihkhjyftytdtvjhbkjnklklnbvvvvvvvvvhvhgzredyvjkjhiohiguyygjpojohuihuybhjmnknklnlkbhjcgcgcjhblk;lkoiouigjggggggggggggggggggggggggggggggggggggggggggggggggggg").'<br>'; echo levenshtein("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","qwertyuioasdfghjklzxcvbnmfghjkyudfghjkcvbnmqwertyudfghjxcvbnqwertyuioplkjhgfdsamnbcvbhfeghipnvcseaaaaaaaaaaaaaaaaaaaaaaaaafjjuuuuuuuuuuuuuuuuuuuuuihkhjyftytdtvjhbkjnklklnbvvvvvvvvvhvhgzredyvjkjhiohiguyygjpojohuihuybhjmnknklnlkbhjcgcgcjhblk;lkoiouigjggggggggggggggggggggggggggggggggggggggggggggggggggg"); ?>
Output for 4.3.2 - 7.1.0
273<br> Warning: levenshtein(): Argument string(s) too long in /in/5Keio on line 28 -1
Output for 4.3.0 - 4.3.1
273<br> Warning: levenshtein() [http://www.php.net/function.levenshtein]: Argument string(s) too long in /in/5Keio on line 28 -1