diff --git a/MD_STD.php b/MD_STD.php index 95be7ef..eeeba8a 100644 --- a/MD_STD.php +++ b/MD_STD.php @@ -51,4 +51,38 @@ class MD_STD { } + /** + * Function checking if a string starts with another. + * + * @param string $haystack String to check. + * @param string $needle Potential start of $haystack. + * + * @return boolean + */ + public static function startsWith(string $haystack, string $needle):bool { + + if (substr($haystack, 0, strlen($needle)) == $needle) return true; + else return false; + + } + + /** + * Function checking if a string starts with any input from the input array. + * + * @param string $haystack String to check. + * @param string[] $needles Array containing potential start values of $haystack. + * + * @return boolean + */ + public static function startsWithAny(string $haystack, array $needles):bool { + + $output = false; + foreach ($needles as $needle) { + $output = self::startsWith($haystack, $needle); + if ($output == true) return $output; + } + return $output; + + } + }