From 4c5097701f5c67985a6aedd617fbfad7a8593868 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Thu, 3 Dec 2020 12:39:47 +0100 Subject: [PATCH] Add wrapper around levenstein that crops strings to the max allowed length --- MD_STD.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/MD_STD.php b/MD_STD.php index bb3838b..327be44 100644 --- a/MD_STD.php +++ b/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); + + } }