diff --git a/includes/common.php b/includes/common.php index 413cae5671..9d79a0936d 100644 --- a/includes/common.php +++ b/includes/common.php @@ -1336,3 +1336,54 @@ function ResolveGlues($tables,$target,$x=0,$hist=array(),$last=array()) { return false; } +/** + * Determine if a given string contains a given substring. + * + * @param string $haystack + * @param string|array $needles + * @return bool + */ +function str_contains($haystack, $needles) +{ + foreach ((array) $needles as $needle) { + if ($needle != '' && strpos($haystack, $needle) !== false) { + return true; + } + } + return false; +} + +/** + * Determine if a given string ends with a given substring. + * + * @param string $haystack + * @param string|array $needles + * @return bool + */ +function ends_with($haystack, $needles) +{ + foreach ((array)$needles as $needle) { + if ((string)$needle === substr($haystack, -strlen($needle))) { + return true; + } + } + return false; +} + + +/** + * Determine if a given string starts with a given substring. + * + * @param string $haystack + * @param string|array $needles + * @return bool + */ +function starts_with($haystack, $needles) +{ + foreach ((array)$needles as $needle) { + if ($needle != '' && strpos($haystack, $needle) === 0) { + return true; + } + } + return false; +}