diff --git a/includes/common.php b/includes/common.php index 98d0eaf756..83ff349cac 100644 --- a/includes/common.php +++ b/includes/common.php @@ -1389,6 +1389,24 @@ function str_contains($haystack, $needles) return false; } +/** + * Determine if a given string contains a given substring. + * Case Insensitive. + * + * @param string $haystack + * @param string|array $needles + * @return bool + */ +function str_icontains($haystack, $needles) +{ + foreach ((array) $needles as $needle) { + if ($needle != '' && stripos($haystack, $needle) !== false) { + return true; + } + } + return false; +} + /** * Determine if a given string ends with a given substring. * @@ -1406,6 +1424,24 @@ function ends_with($haystack, $needles) return false; } +/** + * Determine if a given string ends with a given substring. + * Case insensitive. + * + * @param string $haystack + * @param string|array $needles + * @return bool + */ +function iends_with($haystack, $needles) +{ + $lower_haystack = strtolower($haystack); + foreach ((array)$needles as $needle) { + if (strtolower($needle) === substr($lower_haystack, -strlen($needle))) { + return true; + } + } + return false; +} /** * Determine if a given string starts with a given substring. @@ -1423,3 +1459,21 @@ function starts_with($haystack, $needles) } return false; } + +/** + * Determine if a given string starts with a given substring. + * Case insensitive. + * + * @param string $haystack + * @param string|array $needles + * @return bool + */ +function istarts_with($haystack, $needles) +{ + foreach ((array)$needles as $needle) { + if ($needle != '' && stripos($haystack, $needle) === 0) { + return true; + } + } + return false; +}