Add function stri_contains for case-insensitive, but intuitive
str_contains
This commit is contained in:
parent
a1e6d7773b
commit
245d161805
@ -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.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user