From 245d16180570926b1d9c6f5597525e3843d31257 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Tue, 28 Sep 2021 01:15:51 +0200 Subject: [PATCH] Add function stri_contains for case-insensitive, but intuitive str_contains --- src/MD_STD.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/MD_STD.php b/src/MD_STD.php index 1e6b91e..b16e1ea 100644 --- a/src/MD_STD.php +++ b/src/MD_STD.php @@ -174,6 +174,39 @@ final class MD_STD { } + /** + * Function checking if a string contains another in a case-insensitive way. + * + * @param string $haystack String to check. + * @param string $needle Potential start of $haystack. + * + * @return boolean + */ + public static function stri_contains(string $haystack, string $needle):bool { + + if (stripos($haystack, $needle) === false) return false; + return true; + + } + + /** + * Function checking if a string contains any of a given set of strings in a + * case-insensitive way. + * + * @param string $haystack String to check. + * @param string[] $needles Potential values contained in haystack. + * + * @return boolean + */ + public static function stri_contains_any(string $haystack, array $needles):bool { + + foreach ($needles as $needle) { + if (self::stri_contains($haystack, $needle) === true) return true; + } + return false; + + } + /** * Type-safe(r) wrapper around preg_replace. *