Add wrapper around levenstein that crops strings to the max allowed
length
This commit is contained in:
parent
886acead63
commit
4c5097701f
18
MD_STD.php
18
MD_STD.php
@ -430,4 +430,22 @@ final class MD_STD {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper around levenshtein(), that only compares the first 250
|
||||
* characters (levenshtein can't handle more than 255).
|
||||
*
|
||||
* @param string $str1 First string.
|
||||
* @param string $str2 Second string.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public static function levenshtein(string $str1, string $str2):int {
|
||||
|
||||
if (\strlen($str1) > 250) $str1 = \substr($str1, 0, 250);
|
||||
if (\strlen($str2) > 250) $str2 = \substr($str2, 0, 250);
|
||||
|
||||
return \levenshtein($str1, $str2);
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user